DescriptionThe 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 an
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. You do not need to turn in any code for this lab!
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
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 8/2013). 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
equals method in InsecureCreditCard.java, and fill in the code
for the method accordingly. See pp. 302-307 for information on writing an
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...
*** Match found! ***
Diner's Visa MasterClubCard ... of Doom!
We will charge $21.29 on this card.
How to hand in the assignment