Homeworks must be delivered at the deadline date and hour.
(15
points)
Write
a CheckBook and Check class with the following properties:
Consider the Check
class. Each object in this class has the following attributes that are not
visible to the user:
an int: number - giving the check number.
a String: name - the name of the person to whom the check is being
written out to.
a String: date - the date the check was written (stored as a String).
a double: amount - the amount of the check.
The class has two constructors:
·a constructor for blank checks that has a
String parameter for the date and a CheckBook type parameter. The constructor
increments the numChecks instance variable of the CheckBook object which is
explained below.
·a constructor for typical checks that has
two String parameters, a double parameter, and a CheckBook type parameter
defining the name of person to whom the check is being written to, the date the
check was written, the amount the check is made out to and the CheckBook object
that will be used in the same way described for the first constructor.
The class has the following accessor methods:
·getName() - returns the name on the check.
·getAmount() - returns the amount on the
check.
·getDate() - returns the date the check was
written.
The class also has the following mutator method:
·setName(String s) - changes the name on
the check to s.
The CheckBook class keeps track of the number of
checks that have been written (i.e., each time that a Check constructor is
used) using an int called numChecks
that is not visible to the user. Every time a check is written (a Check object
is instantiated), the integer numChecks
is incremented (its initial value is 0) and the attribute number for the new
check is assigned the new value of
numChecks. The CheckBook class should have the proper constructor.
Finally, the CheckBook class has a class method called
getNumChecks() that returns the
number of checks instantiated. Write a CheckTest class that demonstrates the
use of the Check class as detailed as possible. You can add other necessary
methods to the classes.