Composition
, the design technique in OOP to implement a has-a
relationship between objects.ArrayList
Class. ArrayList is a variable-length data structure.Use the start-up code in the following path on MathLAN to complete this assingment.
Please use Eclipse to import files in vendingmachine
directory into a Java project.
/home/jimenezp/csc207/assignments/vendingmachine/
You should have these 6 files:
You will also see 2 text files:
You must use all 6 classes in your solution, although you may modify the design slightly from the suggested one given via the method descriptions and signatures.
Note: there will be errors showing since many of these files have sections where you will need to add code!! You may want to comment out sections while you are developing.
This program contains your main method and is intended to manage the interactions between the user and the VendingMachine
object. As much as possible, make use of the principle of encapsulation, using methods in VendingMachine
to perform tasks and return information that you would see if you were interacting with a tangible vending machine.
Use the Display
class to communicate with the user rather than using System.out.println
. This practice will separate the message from the implementation, and may allow us to revise this program later to implement a more attractive graphical interface once we learn how to use a Drawing Panel in Java.
The interal and external components of the vending machine are shown below:
In a normal operation, the user inserts coins and one-dollar bills until the amount deposited equals the cost of the soda they want. The vending machine either reports that the item is sold out or asks the user to take soda from the beverage receiver. If the amount deposited exceeds the cost of soda, the machine drops coins, which make up difference, into the change receiver. The machine turns on the change light if it lacks (enough) coins to make up the a difference between the cost of a soda and the amount deposited. If the machine lacks (enough) coins to pay the difference, it drops as many coins as it can to the change receiver.
We have simplified the process slightly and will use the Display to provide messages that a sale is successful, the amount of change to take, or that there is not enough change to provide exact change after a transaction. All of these things could be added later if we have time to create a graphical interface.
Complete the definition of a class for each of these pieces in the start-up code. Each class contains appropriate methods, however, you may add additional methods or change these slightly so long as the class as a whole handles similar tasks.
System.out.println
anywhere else in your program except for diagnostic messages (which should be commented out before submission).System.in
). The VendingMachineSim class should create its own Display object that it will use to display messages to the user. You may not use System.out.println
to convey messages in your submitted code.The main
method uses the vending machine pieces explained above through its public methods. The purpose of the main method of this class is:
VendingMachine
constructor, which will use config.dat to create the inventory ArrayList
Your vending machine can use any technique to make change given that the change box contains appropriate coin types to make that change. You do not need to try to implement an efficient algorithm, especially since those generally assume that you have an infinite number of coins of each type!
Note that after each successful purchase, the deposited coins (not bills) are moved into the second coin box so that you have more coins available with which to make change. You may want to have a private field in the Bill Box to track the number of bills associated with the current transaction. Note also that, since we never ask for the total amount of money in the machine itself, do not need to track the total number of bills … only those associated with the current transaction.
When using Eclipse, your config.dat
file should be located in the project directory at the same level as the /bin and /src directories.
The vending machine directory contains sample.txt
that shows a sample run of the program. It shows the interactions of a couple of purchases based on the default config.dat
file.
You need to test your program thoroughly; the provided files are a starting point (basic example). You should test your program with both successful and unsuccessful transactions. You must at least do:
Run your program and submit a text file showing the output of the test. If you are running it in Eclipse, you should copy and paste the output from the console frame.
Create a folder in the project directory for your documentation and use the Javadoc utility to generate the documentation of your classes.
You MUST include an Academic Honesty Statement in your client program. If you do not, your submission will be assessed a 10% penalty.
Your program must compile and run for the graders. If it does not, your submission will not be graded until the corrected file is received and you will be assessed a 20% penalty. You will need to use a token for resubmitting.
You must submit all of your source code, any configuration files that you created (other than the one provided) and a text file that shows a test run of your program. This must be in a compressed tar.gz file (see Lab 1 for instructions on how to create this file from your directory). Files that are in a .zip format will lose one point.
This assignment is worth up to 25 points based on the following:
Good practices
Meet Requirement specification
System.out.println
used only in Display.javaApply object-oriented design principles to the creation of Java programs
Handling errors