COMP 110-003 Spring 2013

Lab 6

No submission required


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 an equals method.

Create a new Java project in Eclipse and copy the code from both and into Java classes in that project. Read through both files and try to understand what is happening. If you try to compile, 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 .java file for this lab!

  1. 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.

  2. 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 to get the program to do what it is supposed to do. Read the description of the equals method in, and fill in the code for the method accordingly. See pp. 302-307 for information on writing an equals method.

  3. 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: 7/2013
    Checking: 8/2013
    *** Match found! ***
    Diner's Visa MasterClubCard ... of Doom!

    We will charge $21.29 on this card.