Lab 3: Credit Cards
Steven K. Andrianoff
Robert Harlan
David Levine
Computer Science Department
St. Bonaventure University
Copyright, 2003
Due:
Friday, February 6
Objective:
This lab provides a CreditCard class and requires students to create CreditCard
objects and exercise the CreditCard methods. Students will test the behavior of
the CreditCard methods without having access to the source code for the
CreditCard class.
Background:
For this lab you will be provided with a CreditCard class. You will not have
access to the source code (Java code) for the class. However the class has the
following methods:
- A constructor that takes no arguments
- A second constructor that takes a single integer (numeric) argument
- A pay method with the signature:
public void pay(int amount)
- A charge method with the signature:
public void charge(int amount)
- A limit method with the signature
public int limit()
- A totalDue method with the signature
public int totalDue()
- A minimumDue method with the signature
public int minimumDue()
You can probably infer the behavior of the methods from their names. Your task
in the lab is to exercise the methods to precisely determine their behavior.
- Launch the Eclipse development environment. Create a new project named Lab3.
Have your lab instructor help you add the jar file
Lab3.jar
to your project.
Create a class named CardTester. As in Lab 2, select File / New / Class.
Make sure the source folder is Lab3. Name the class CardTester. Make
sure the Modifier public is selected and the public static void
main(String[] args) checkbox is checked. Click Finish. The
editor window should open a file named
CardTester.java
with a skeleton of the CardTester class with a main method in it.
All the coding in the succeeding steps involve writing statements in the main
method of the CardTester class. Begin by modifying the comments to include your
names and the date. For a description just say that this is a program to test
the CreditCard class.
- Add statements to the main method to declare then create a CreditCard object.
What is the initial limit of the card? Write statements to determine the limit
and display it.
(For the purposes of this lab, use System.out.println() for
displaying information in the console window. Also, label any displayed
information, for example,
System.out.println(“Limit: “
+ amt); )
How much is owed initially? What is the minimum payment initially? Record
your results and provide a copy of the statements you used to find and
display this information.
- There is a second constructor for the CreditCard class that takes a single integer argument.
Create a card using this constructor and determine the initial limit, amount
owed, and minimum payment. Describe how this constructor is different from the
constructor that takes no arguments. Record your results and
provide a copy of the statements you used to find and display this information.
- Modify the program from Step 3 by adding statements to make a charge on the card after it is created. How does the charge affect
the limit? How does it affect the amount owed? How does it affect the minimum
payment? Add statements to perform these tests. Record your results and
provide a copy of the statements you used to find and display this information.
- Further modify the program
from Step 4 to make a payment on the card after the charge. How does the payment affect the limit? How does
it affect the amount owed? How does it affect the minimum payment? Add
statements to perform these tests. Record your results and
provide a copy of the statements you used to find and display this information.
- Describe how the
minimum payment is calculated. Be careful, there may be special cases.
Provide a copy of the statements you used to determine how the minimum
payment is calculated.
Describe the results of your tests.
- Can you find charges that
cause errors to be displayed? (Hint: there are two types of charges that will
result in error messages.) Provide a copy of the statements that resulted in errors and
record the error messages.
- Comment out all the
statements except the statements to create the card and statements to make a
single charge. Display the current limit, amount owed, and minimum payment
after this charge. Now experiment with various payments. What happens to the
limit, the amount owed, and the minimum payment when a full payment is made?
What happens to these when a partial payment is made? Provide a copy of the statements
you used to answer these questions and the results you obtained.
- Can you find payments that cause errors to be displayed? (Hint: there three types of
payments that will result in error messages.) Provide a copy of the statements that resulted in errors and
record the error messages.
- Make sure all of your tests are still in the main method even though most of them may be
commented out. Print a copy of the file CardTester.java
and hand it in with your lab
write-up.
Extra Credit:
Run similar tests on another class named ImprovedCreditCard. Create a new class called ImprovedCardTester with a main
method in it.
The ImprovedCreditCard class has the same set of methods as the CreditCard class
however one or more of the methods behave differently. Write statements to test
this new class. What methods behave differently? Carefully describe the
different behavior based on tests you write. Provide a copy of the statements you used
to investigate the different behavior and how the behavior is different.
Make sure the comments in the file
ImprovedCardTester.java
are appropriate then
print a copy of the file
ImprovedCardTester.java
and hand it in with your lab
write-up.
Hand in:
The write-up you hand in for this
lab should include:
- answers to questions in Steps 2-9
- the record of results and a copy of statements used as
requested in Steps 2-9
- a printout of the program (source code) requested in Steps 10
- if you do the Extra Credit, answer the questions, record
the results of your tests, include a copy of the statements used, and
provide a printout of the source code
Help Policy:
Help Policy in Effect for
This Assignment: Group Project with Limited Collaboration
In particular, you may
discuss the assignment and concepts related to the assignment with the following
persons, in addition to an instructor in this course: any member of your
group; any St. Bonaventure Computer Science instructor; and any student enrolled
in CS 131.
You may use the following
materials produced by other students: materials produced by members of your
group.