Project
Turn in your work under the Google Drive folder and
Google Classroom according to general guidelines.
001-CashRegister
(Total 100 pts.)
Implement a CashRegister class
that models a self-service cash register in the US. Imagine the customer scans
the price tags of various items, sees the total purchase amount, and deposits the
at least the required amount of money in the machine. The machine then dispenses
the change.
step 1 (0 pts.)
Find
out which methods you are asked to supply.
In a simulation, you do not have to provide every feature
that occurs in the real world—there are too many. Thus, you must first clarify
what the project will entail. In this project, you should at least design a
class to simulate the following aspects of the self-service cash
register:
·
Process the price of each purchased item (use console input
from user for each item’s price)
·
Show the total purchase amount to the customer
·
Receive payment. (use console input from user for payment
amount)
·
Calculate and return the change (Use console output to show
the change that needs to be returned)
step 2 (5 pts.)
Specify the public interface.
Turn the list in Step 1 into a set of methods, with
specific types for the parameter variables and the return values.
·
...
·
...
·
...
·
...
To complete the public interface, you need to specify the
constructors. Ask yourself what information you need to construct an object of
your class. Sometimes you will want two constructors: one that sets all
instance variables 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
might start out with some coins and bills so that we can give exact change, but
that is beyond the scope of our assignment. Thus, add a single constructor:
·
...
step 3 (10 pts.)
Document
the public interface.
Use meaningful
comments, that describes the class, constructors, and its methods in the JavaDoc
style, using @param, @return when necessary. Make sure to update the
documentation as you improve the program.
step 4 (5 pts.)
Determine instance variables.
Ask yourself what information an object needs to store to
do its job. Remember, the methods can be called in any order. The object needs
to have enough internal memory to be able to process every method using just
its instance variables and the parameter variables. Go through each method,
perhaps starting with a simple one or an interesting one and ask yourself what
you need to carry out the method’s task. Make instance variables to store the
information that the method needs.
·
...
·
...
Just as importantly, do not introduce unnecessary
instance variables. If a value can be computed from other instance variables,
it is generally better to compute it on demand than to store it.
step 5 (10 pts.)
Implement constructors and methods.
Implement
the constructors and methods in your class, one at a time, starting with the
easiest ones.
Make
sure to automatically reflect the most recent item cost and the total purchase amount
so far to the customer after each processed item.
Be careful, a customer might provide two separate
payments, such as two $10 bills, and the machine must process them both.
Remember, methods can be called more than once, and they can be called in any
order. Also do not forget to reset the cash register for the next sale after
you compute the change due.
If you find that you have trouble with the
implementation, you may need to rethink your choice of instance variables. It
is common to start out with a set of instance variables that cannot accurately
reflect the state of an object. Do not hesitate to go back and add or modify
instance variables.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
27 | 28 | 29 | 30 | 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |