Lab 6
Description
The purpose of this exercise is to give you some more practice with a bunch of things we have learned so far, up to and including how to write anequals
method.
Create a new Java project in Eclipse and copy the code from both Lab6.java and InsecureCreditCard.java into Java classes in that project. Read through both files and try to understand what is happening. If you try to compile Lab6.java, you will see that it has several syntax errors. Your goal in this exercise is to correct the syntax errors, and then to correct logic errors in the code.
Each time you find an error in the code, correct it and write down (in a text file) what you found.
Start off by correcting one syntax error at a time. For example, when you first
compile the program, start by correcting the very first error: the keyword class
is misspelled at the top of the program. Fix that error, and then rerun (recompile) to find
out what the next error is. Recompile again, and fix the next error, until there are
no more syntax errors.
Now there are a few logic errors in the code. Try running the program to see what happens. The nested for loops are supposed to iterate over several years and months to find a matching credit card expiration date (which is supposed to be 6/2015). However, a match is not being found. Why not? Write down any logic errors you find. Again, fix one logic error at a time and retest the program.
Hint: you will also need to change the equals
method inside
InsecureCreditCard.java to get the program to do what it is supposed to do. Read the description
of the equals
method in InsecureCreditCard.java, and fill in the code
for the method accordingly. See pp. 327-331 for information on writing an equals
method.
When the program is running correctly, the output should look like the following:
Checking: .... a whole bunch of these lines that iterate through months and years...
Checking: 5/2015
Checking: 6/2015
*** Match found! ***
Diner's Visa MasterClubCard ... of Doom!
1234567812345678
06/2015
We will charge $21.29 on this card.
Grading
How to hand in the assignment