Project 2 — Late Night Snack Machine

Assigned Monday, March 7, 2011
Program Due 11:59pm, Sunday, March 20, 2011
Weight 7%
Updates Monday, March 14th:
A minor change was made to Project2.java such that the add cookies/mints dialogs will now allow you to attempt to add up to 100 items at a time. This should make testing the maximum number of cookies/mints cases slightly easier. You may update your Project2.java to this newer revision if you like.

Objectives

To continue to gain experience in the following areas:

Project Description

In this project, you will be part of a team working on a simulation of a vending machine that sells snacks to hungry computer science students working late at night on their CMSC 202 projects. The simulation will be comprised of an application that uses the snack machine and a collection of classes that implement the snack machine’s functionality. The user interface will be developed by another group of programmers. Your assignment is to design and implement the supporting classes.

Designing this project will be an in-class student exercise based on the specification below. In class, we will identify the classes necessary for the simulation and specify the required interface between these classes and the user interface. The user interface will be provided for you as Project2.java.

Project Specification

Our programmer’s vending machine sells only bags of cookies (for that late-night sugar boost) and breath mints (for some early morning freshness), both of which are necessities for computer science students everywhere. Breath mints cost 35¢ and come in virtually all colors (all of the mints in a single package are of the same color). Cookies cost 65¢ per bag and come in three flavors — chocolate chip, oatmeal, and lemon. When you purchase a package of mints, you will not know the color of the mints; when you purchase a bag of cookies, you will not know their flavor. That’s because the machine is stocked by a group of pranksters from the Information Systems Department!

To use the snack machine, the CMSC 202 student inserts some change (nickels, dimes and/or quarters only) and pushes either the “Buy Mints” button or the “Buy Cookies” button. If the student has inserted the correct amount of money and the snack machine is not sold out, the application displays a “success” message. The “success message” when a package of mints is purchased displays the color of the mints as part of the message. The “success message” when a bag of cookies is purchased indicates the flavor. If the purchase fails, the application displays a “failure” message. Snacks are sold in “first-in, first-out” order (oldest ones first) — no one wants a stale bag of cookies at 4:30 in the morning!

There are responsibilities that come with having the snack machine on campus. These responsibilites include stocking the snack machine by adding more mints and bags of cookies, reporting the number of packages of mints and bags of cookies currently in the machine, and reporting the contents of the change drawer (number of nickels, dimes, quarters, and total amount of money).

Other Snack Machine Details

  1. The snack machine holds a maximum of 75 packages of mints and 60 bags of cookies.
  2. The user interface code will not provide any explicit user input validation. All input validation must be performed by the snack machine.
  3. Your snack machine can only accept exact change. If anything but the cost of the item is entered, the purchase request must fail.
  4. Since the snack machine only accepts exact change, its change drawer will be initially empty and it can only dispense one snack at a time.
  5. The snack machine initially contains no mints or cookies. A user has to add snacks before anyone can buy a snack.

Project2.java requires a specific set of classes to be created with specific public interfaces. We have generated Javadoc APIs (i.e. the public interface) for the classes you are required to implement for this project.

The following 2 classes have been provided for you on this assignment:

You are not permitted to make any changes to Project2.java or CookieFlavors.java.

However, you are welcome to add additional members/methods (public or private) to the other classes referenced in the Javadocs. Additionally, you are welcome to add additional helper classes as you see fit.

Snack machine screen shots from the provided GUI can be found here:

Requirements and Hints

  1. RequirementProject2.java and CookieFlavors.java may be downloaded from this project description. You must write all other classes. You MUST NOT edit these files.
  2. Requirement — Each file for this project must be part of a package named proj2.
  3. Requirement — You MUST write your snack machine code in SnackMachine.java.
  4. Requirement — All classes that you implement must have a main() method. Unit test each class separately by using its main(). See Testing Your Class in Main for help writing main to test your class.
  5. Requirement — All files must have a class header comment with an appropriate class invariant(s) description.
  6. Requirement — All methods of the snack machine class must be fully commented including pre- and post-conditions.
  7. Requirement — We will use Java’s Color class to represent the colors of the mints. Check out the Java API for details about this class. To use Java’s Color class in your code, you must import the class file into the files that use Color objects.
    import java.awt.Color;
  8. Requirement — An enumeration must be used for the flavors of the bags of cookies.
  9. Hint — Some of your classes may be immutable. That means that making copies of them is not necessary since "aliasing" does no harm. Use this fact to make your code easier, but be sure you can tell when it’s safe.
  10. Hint — formatting strings can be accomplished with String’s static format method (e.g. for neatly displaying the total amount of money).
  11. Testing — Your project might have its functionality tested in the following ways:
    • Basic Test Cases — these might be tests such as adding a single cookie or mint, buying a single cookie or mint, or displaying the money in the snack machine.
    • More Complex Cases — these might be tests such as adding multiple cookies or mints, purchasing a cookie or mint with a sufficient number of nickels, dimes, and quarters.
    • Atypical Cases — these might be tests that attempt to break your code based on input or class invariant violations. These might buy cookies with incorrect money values, add too many cookies or mints to the snack machine, and more.

Project Policy

This project is considered an OPEN project. Please review the OPEN project policy on the course website.

As you will no doubt discover, this project is a variation on a project that has been assigned before. Copying code from anyone is a violation of the project policy, even copying code from someone who was in CMSC 202 during a previous semester. Be advised that the programs that compare projects will compare your project with those from past semesters as well as those from this semester.

Grading

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

Project Submission

  1. submit cs202 Proj2 <all .java files you create>. Submit only your .java files (not .class files or any other files). DO NOT submit Project2.java or CookieFlavors.java. If either file is submitted, it will be deleted before your project is graded.
  2. Use submitls to verify that your files are in your submittal directory

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 compiler errors and a reduction in your grade.

Avoid unpleasant surprises!