Homework #2

CS35 Spring 2002

Homework 2
Due: Thursday February 7, before 2am (late Wed. night)

CONTENTS

You should work by yourself on this assignment.


ASSIGNMENT

Problem 1: GradBookEntry Class Starting with the classes given below that are similar to the Person and Student classes we covered in class, implement a GradeBookEntry class as shown in
Figure 1.

Figure 1:

Include a main method to the GradeBookEntry class that does the following:

Problem 2: Credit Cards
You will write a Java program that allows a user to create a new credit card of one of three types: a regular card, a gold card, or a last-chance card. Next your program will enter a loop that will:

The menu will have the following options:
  1. Use credit card
  2. Make a payment
  3. Quit
When the user selects option 3, to quit, your program should terminate.

Characteristics of each type of credit card:


Implementation Details and Requirements

Starting with the CreditCard class given in the book implement features specified in the book problems R-1.3 and R-1.4. For R-1.4, use the regular credit card interest rate and limit; in your program, regular credit card objects will be instances of the CreditCard class. Each time a user makes a payment, you should charge interest on any unpaid balance (note: unlike a real credit card, you do not need to keep track of time in your program and charge interest when a payment is late, instead every time a user chooses to make a credit card payment your program should check to see if interest should be charged based on the remaining balance alone).

Once you have added these changes to the CreditCard class and you have tested that they work correctly, do the following:

  1. Create a GoldCard class that is a subclass of CreditCard. The status information of a GoldCard should include the number of frequent flyer miles accumulated so far.
  2. Create a LastChanceCard class that is a subclass of CreditCard. Override the makePayment method to check if three full payments have been made in a row, and if so modify the interest rate and limit accordingly.
Specific Requirements

To implement some of the functionality in the GoldCard and LastChanceCard classes, you may need to add (or change) methods in the CreditCard class as well as add data members to this class.

Do not worry about formating floating point values for this assignment. However, if you would like to play around with number formating, take a look at the API documentation for the DecimalFormat and NumberFormat classes. Here is an example of how you could format dollar amounts to print the retail price of an Auto object from your last homework assignment:

        NumberFormat mf = NumberFormat.getCurrencyInstance(Locale.US);
        String priceOutput = mf.format(this.retailPrice());
        System.out.println(" retail price is " + priceOutput );

Classes

You should use the following classes as starting points for your programs:


HAND IN

Using cs35handin, hand in a single tar file containing all the Homework 2 .java files necessary for compiling and running your solutions to both problem 1, and 2 (including all of the files that we give you that you use in your solution), and a copy of your Makefile.