Java Reference
In-Depth Information
To complete the public interface, you need to specify the constructors. Ask
yourself what information you need in order to construct an object of your class.
Sometimes you will want two constructors: one that sets all fields to a default and
one that sets them to user-supplied values.
In the case of the cash register example, we can get by with a single constructor
that creates an empty register. A more realistic cash register would start out with
some coins and bills so that we can give exact change, but that is beyond the scope
of our assignment.
Thus, we add a single constructor:
ȗ public CashRegister()
99
100
Step 3 Document the public interface.
Here is the documentation, with comments, that describes the class and its
methods:
/**
A cash register totals up sales and computes
change due.
*/
public class CashRegister
{
/**
Constructs a cash register with no money
in it.
*/
public CashRegister()
{
}
/**
Records the sale of an item.
@param amount the price of the item
*/
public void recordPurchase(double amount)
{
}
/**
Search WWH ::




Custom Search