CMSC 202 Project 1
Pop's Convenience Store
Assigned Monday, September 20
Program Due 10:00am, Wednesday, September 29
Weight 6%
Updates  

Objectives

To gain experience:

  1. Implementing and using classes
  2. Separating an OO program's user interface code from its application code
  3. Performing console input/output in Java
  4. Using and manipulating arrays
  5. Documenting classes
  6. Documenting methods

Project Policy

This project is considered an OPEN project. Please review the open project policy before beginning your project.

Project Analysis

Code from this project will be reviewed in class as noted on the schedule as "Project 1 Analysis." If you would like your code to be reviewed in class, please contact your instructor. Your name will be held in strict confidence. This practice has worked extremely well in the past. It is a wonderful way to compare and contrast the different designs that people have used.

Project Overview

We all encounter cash registers when we do our shopping. Some of us have even operated a cash register as part of our job.

Your first project will be to implement a simple cash register class. You will also write a user interface (UI) class that contains main(). The UI class will be used to perform user input/output and to invoke the appropriate methods of the cash register class. The program will be driven by a simple text-based menu with 1-character menu options.

Project Specification

Congratulations! Uncle Joe has just made you the manager of his convenience store. Pop's Convenience Store is a small shop in downtown Arbutus. The store has two cash registers. Your program will simulate some basic cash register functionality. Assume, for simplicity, that a cash register can only contain bills (ones, fives, tens, and twenties). A cash register can also either be locked (it cannot be used) or unlocked (it can be used). The registers are referred to by number (i.e. 1 or 2).

When your program starts, it will automatically "open" the convenience store by unlocking both registers, asking the user to input the number of each of the four bill demoninations to put into each register (each register gets the same number of each bill), and putting the bills into each register. The program should ask for the number of bills in the following order: ones, fives, tens, then twenties.

Next, the following menu will should displayed.

A - Add money
R - Remove money
T - Transfer money
L - Lock register
U - Unlock register
S - Display register state
C - Close the store and quit

Further explanation of these options is as follows.

Add money - Ask the user which register (1 or 2) to add money to and then the amount to add (number of ones, fives, tens, and twenties). Add the bills to the register.

Remove money - Ask the user which register to remove money from and then the amount to remove (number of ones, fives, tens, and twenties). Remove the bills from the register.

Transfer money - Ask the user which register to transfer the money from, then the number of ones, fives, tens, and twenties to transfer. Transfer the money.

Lock register - Ask the user which register to lock, then lock the register.

Unlock register - Ask the user which register to unlock, then unlock the register.

Display register state - Ask the user which register's state to display, then display the state. A register's state consists of: whether the register is locked or unlocked, the numbers of ones, fives, tens, and twenties in the register, and the total amount of money in the register (in dollars). Display each piece of data on a separate line. Make sure to give each piece of data an appropriate label.

Close the store and quit - Close your store by removing the money from both registers, locking both registers, displaying the state of both registers, and exiting the program.

Note that, where relevant, the cash register on which to perform an action (1 or 2) must be specified before any other inputs needed. In general, be sure to perform the tasks listed for each command in the exact order specified above and prompt for the input needed in the exact order specified above.

Project Hints, Notes, Requirements, Restrictions
  1. The package name for this project should be proj1.
  2. The user interface class (that contains main) should be called Project1. The cash register class should be called CashRegister.
  3. In keeping with the principle of separation of user interface and applications code, the CashRegister class should NOT perform any user input or output. All user input/output should be performed by main() or one of main's helper methods.
  4. Be sure that you follow the OOP principle of encapsulation. Don't use accessors and mutators to write procedural code in main; call appropriate CashRegister methods instead.
  5. ALL methods of the Project 1 and CashRegister classes must have appropriate method header comments, including pre- and post-conditions, as shown in the course coding standards and discussed in class. Make sure that your methods catch any violated preconditions.
  6. Both the Project1 and CashRegister classes should have file header comments, but you may omit the Class Invariant portion (for now).
  7. Use the Scanner class for user input as discussed in lab. Be sure to create only one Scanner object, which should be an instance variable in the Project1 class. If you do not follow this procedure, it is possible that the automated grading script will not work with your program (and that's not good!).
  8. Since main is by definition a static method, any constants, instance variables, and helper methods that are also defined within the Project1 class and used by main should be defined as private static.
  9. Generally speaking, each main menu selection corresponds to a method of the CashRegister class.
  10. The CashRegister class must store the quantities of all bills in a one-dimensional, four-element array. Store the number of 1's in the 1st position (note "position," not "index"), the number of 5's in the 2nd position, the number of 10's in the 3rd position, and the number of 20's in the 4th position. Note that this does *not* mean that the Project1 class must store the bills in this manner. (Remember information hiding?)
  11. Input Guarantees and Error Handling
    1. All user input is guaranteed to be of the correct type, but not necessarily a valid value.
    2. Menu selections are guaranteed to be entered as a single character, but may be either upper- or lower-case. In the case of an invalid menu selection, display an informative error message to the user and redisplay the menu.
    3. In the case of the selection of a register (1 or 2), if the user enters other than 1 or 2, display an appropriate error message and reprompt the user for the register number.
    4. For all other errors (e.g. attempting to add money to a locked register, negative number of bills), display an appropriate error message and return the user to the main menu.

Grading

See the course website for a description of how your project will be graded.


Project Submission

Before submitting your project, be sure to compile and test your code on the GL system. See the Project Compilation section of the course Projects page for details on how to compile and execute your project on GL.

Assuming you've used the specified file names, submit your project by typing the command

submit cs202 Proj1 Project1.java CashRegister.java See the Project Submission section of the Projects page for detailed instructions.

You may resubmit your files as often as you like, but only the last submittal will be graded and will be used to determine if your project is late. For more information, see the Projects page on the course web site.

More complete documentation for submit and related commands can be found here.

Remember -- if you make any change to your program, no matter how insignificant it may seem, you should recompile and retest your program before submitting it. Even the smallest typo can cause errors and a reduction in your grade.