Exam 4: A Practice Exam (for the Final)

The purpose of this on-line exam is to measure your facility in programming and give you a warm-up for the final.

However, some problems that might occur are really associated with using CodeWarrior and/or Macintosh.  If you've got a problem with something other than debugging your code, raise your hand and either a CA or I will come to help.


The exam has two problems. Because this is a 50-minute exam, the two problems will be simpler than the corresponding problems on the three hour final.  Unlike the final exam, you will be given partial credit if your code is reasonably close to correct.
 

The first problem (worth 40% of this exam) requires you to create a simple class. It appears here.
 

The second problem involves a collection class of objects from the first problem; a correct (but minimal) version of the class from problem one will be provided.  On this exam, you will have a choice of writing either of the following methods for the collection class:

          an insert method (described here)
or
          a remove method (described here)

Select your second problem carefully since one of these two methods will likely simpler to code.


Problem 1 (40%):

You are to implement a Stamp class that is fit for maintaining information about a stamp collection.  For this simple version, the class only needs to keep track of the following:

• the description of the stamp (e.g.,  “John Kennedy profile in blue (US 1963)”)
• the face value of the stamp (e.g.,  5 cents)
• the appraised value of the stamp (e.g., 0.60 dollars)
The StampTester class contains a program whose output is indicated below. Create the Stamp class to support the program so that it produces the output indicated.

Creating two stamps...
 

Printing them...
Kennedy (US 1963), face value: 5 cents, appraised value: 0.6 dollars
Lincoln (US 1923), face value: 1 cents, appraised value: 42.6 dollars

Changing some values
Changing the appraisal of Kennedy (US 1963) from 0.6 dollars
Changing the appraisal of Lincoln (US 1923) from 42.6 dollars

Printing them again...
Kennedy (US 1963), face value: 5 cents, appraised value: 0.75 dollars
Lincoln (US 1923), face value: 1 cents, appraised value: 72.4 dollars
 


Problem 2 option 1: the insert method

Implement the insert method for the collection class where the insert semantics are as follows:

The insert method takes two parameters: the first parameter is the object to be inserted; the second parameter is the index of the array at which to place the object.  All objects in the list that follow the insertion position are shifted to the right. If the value of the index parameter is inappropriate for the logical size of the array, a message is to be printed.

Once you implement the insert method and run InsertTester, you should see the following output:
 

Initial data loaded into StampList...
    StampList[used=4/length=4
      values[0]= Liberty (US 1955), face value: 5 cents, appraised value: 20.0 dollars
      values[1]= Lincoln (US 1940), face value: 3 cents, appraised value: 15.05 dollars
      values[2]= Blue Loon (Can 1970), face value: 25 cents, appraised value: 10.5 dollars
      values[3]= Young Elvis (US 1995), face value: 33 cents, appraised value: 1.35 dollars
 ]
 

INSERTION TESTS...

Insert at index 4 of T. Roosevelt (US 1940), face value: 1 cents, appraised value: 35.4 dollars
    StampList[used=5/length=8
      values[0]= Liberty (US 1955), face value: 5 cents, appraised value: 20.0 dollars
      values[1]= Lincoln (US 1940), face value: 3 cents, appraised value: 15.05 dollars
      values[2]= Blue Loon (Can 1970), face value: 25 cents, appraised value: 10.5 dollars
      values[3]= Young Elvis (US 1995), face value: 33 cents, appraised value: 1.35 dollars
      values[4]= T. Roosevelt (US 1940), face value: 1 cents, appraised value: 35.4 dollars
 ]

Insert at index 6 of LOVE (US 1975), face value: 31 cents, appraised value: 0.35 dollars
INVALID INSERT: 6 is not a valid index
Insert at index -5 of LOVE (US 1975), face value: 31 cents, appraised value: 0.35 dollars
INVALID INSERT: -5 is not a valid index
 

Insert at index 2 of LOVE (US 1975), face value: 31 cents, appraised value: 0.35 dollars
    StampList[used=6/length=8
      values[0]= Liberty (US 1955), face value: 5 cents, appraised value: 20.0 dollars
      values[1]= Lincoln (US 1940), face value: 3 cents, appraised value: 15.05 dollars
      values[2]= LOVE (US 1975), face value: 31 cents, appraised value: 0.35 dollars
      values[3]= Blue Loon (Can 1970), face value: 25 cents, appraised value: 10.5 dollars
      values[4]= Young Elvis (US 1995), face value: 33 cents, appraised value: 1.35 dollars
      values[5]= T. Roosevelt (US 1940), face value: 1 cents, appraised value: 35.4 dollars
 ]

Insert at index 0 of Elizabeth II (GB 1950), face value: 10 cents, appraised value: 18.45 dollars
    StampList[used=7/length=8
      values[0]= Elizabeth II (GB 1950), face value: 10 cents, appraised value: 18.45 dollars
      values[1]= Liberty (US 1955), face value: 5 cents, appraised value: 20.0 dollars
      values[2]= Lincoln (US 1940), face value: 3 cents, appraised value: 15.05 dollars
      values[3]= LOVE (US 1975), face value: 31 cents, appraised value: 0.35 dollars
      values[4]= Blue Loon (Can 1970), face value: 25 cents, appraised value: 10.5 dollars
      values[5]= Young Elvis (US 1995), face value: 33 cents, appraised value: 1.35 dollars
      values[6]= T. Roosevelt (US 1940), face value: 1 cents, appraised value: 35.4 dollars
 ]
 


Problem 2 option 2: the remove method

Implement the remove method for the collection class where the remove semantics are as follows:

The remove method takes no parameters. It removes the object with the lowest appraised value and all other objects originally in the list are shifted one position to the left.

Once you implement the remove method and run RemoveTester, you should see the following output:

Initial data loaded into StampList...
    StampList[used=4/length=4
      values[0]= Lincoln (US 1940), face value: 3 cents, appraised value: 15.05 dollars
      values[1]= Young Elvis (US 1995), face value: 33 cents, appraised value: 1.35 dollars
      values[2]= Liberty (US 1955), face value: 5 cents, appraised value: 20.0 dollars
      values[3]= Blue Loon (Can 1970), face value: 25 cents, appraised value: 10.5 dollars
 ]
 

REMOVAL TESTS...

Removing element
    StampList[used=3/length=4
      values[0]= Lincoln (US 1940), face value: 3 cents, appraised value: 15.05 dollars
      values[1]= Liberty (US 1955), face value: 5 cents, appraised value: 20.0 dollars
      values[2]= Blue Loon (Can 1970), face value: 25 cents, appraised value: 10.5 dollars
 ]

Removing element
    StampList[used=2/length=4
      values[0]= Lincoln (US 1940), face value: 3 cents, appraised value: 15.05 dollars
      values[1]= Liberty (US 1955), face value: 5 cents, appraised value: 20.0 dollars
 ]

Removing element
    StampList[used=1/length=4
      values[0]= Liberty (US 1955), face value: 5 cents, appraised value: 20.0 dollars
 ]

Removing element
    StampList[used=0/length=4
 ]

Attempting removing
    StampList[used=0/length=4
 ]