Simulate the use and maintenance of a vending machine

Assignment Help JAVA Programming
Reference no: EM131585956

Overview
In this assignment you will write a set of classes that work together to simulate the use and maintenance of a vending machine. Your program should read in an input "command" file that will contain commands to stock the vending machine with products, take inventory of the machine, select items from the machine, and restock products. Your program will consist of three classes: Product, VendingMachine, and VendingMachineDemo.

Assignment Instructions:
The Product class is provided for you. Download and include in your java project.

Product class: This class should represent a product in the machine. The class's responsibilities are to know the product name, cost of the product, and the product's inventory (number of instances of that particular product in the machine). For example, M&Ms can be a product where the name is "M&Ms", the cost is $0.75, and the inventory is 5 meaning there are 5 M&M items in the machine.

The methods that are provided for the Product class are the following:
+ Product (name : String, cost : double, inventory : int): Constructor for the Product class
+ getName : String - Accessor method that should return the name of the product
+ getCost: double - Accessor method that should return the cost of the product
+ getInventory : int - Accessor method that should return the number of this particular type of product in the vending machine's inventory.
+ setInventory(invent : int) : void - Mutator method that should update the products inventory. This method is called when the product is restocked into the machine.
+ dispense : void - Called when an instance of the product is dispensed from the machine. The inventory should be decremented by one.

The classes you need to design and implement are the following:

VendingMachine class: This class should represent the vending machine object. The class's responsibility is to hold an inventory of products and to know how much money is in the machine to be used for change. The products should be held in a two dimensional list where "a 1" represents element [0,0] in the list, "a 2" represents [0,1], "b 1" represents [1,0], etc. The maximum number of rows and columns is both 4 therefore the machine can hold 16 different products. For each product, the maximum number of inventory is 5.

The methods that should be implemented for the VendingMachine class are the following:
+VendingMachine(changeAvailable : double) - constructor for the VendingMachine class.
+ deposit(amount : double) : void - Maintenance operation where money is added to the machine to be used for change. This method should modify the change available in the machine.
+ takeInventory : void - Maintenance operation where the inventory of the machine is collected and printed. The method should iterate over each slot in the machine and print the product name, cost, and inventory at that particular slot. It should also print the amount of change currently in the machine.
+ selectItem ( row : char, column : int, amount : double) : void - This method represents a selection being made on the vending machine. The parameters row and column will be something like "b, 2" which can be used to resolve the location slot where the product is stored, and the amount parameter is the amount of money deposited into the machine by the customer. The method should determine which product is contained at the provided location and validate that the cost of the product is less than the amount deposited. The method should print either the amount of change owed back to the user or an error message saying that the selection cannot occur either because the product is out of stock or the amount deposited is not enough. Finally, if the selection was valid the inventory should be updated in the corresponding product by calling the dispense method on the Product object.

+ stock (row : char, column : int, name : String, cost : double, inven : int) : void - This method will stock the machine with the product. This method assumes that the provided location is an empty slot and a new instance of a product should be created and stored in the slot.

+ restock (row : char, column : int, invent : int) : void - This method will restock the machine with the product at the provided location. Unlike the stock method you can assume that the product is already contained at the location. The products inventory should be updated based on the parameter inven.

VendingMachineDemo class: This class will represent the main class in the program. Your program should prompt the user to enter a filename that contains the commands for the program and open the specified file for reading. The program should then read in each command line by line and execute each command one at a time. To execute each command, the program should interact with the vending machine object based on the command parameters. The valid commands and formats are the following:

initialize <amount>

Create a new vending machine and initialize the change available to

<amount>. It can be assumed that this will be the first command and there will only be 1.

stock <row> <column> <name> <cost> <inventory>

Stock the vending machine at location <row>, <column> with a new product with

 

associated <name>, <cost>, and <inventory>

inventory

Take inventory of the vending machine, a report of all the products and the amount of change currently available in the machine should be generated.

select <row> <column> <amount>

Select and dispense an item from the machine at location

<row>, <column> with

<amount> of change deposited for the purchase. The program should either simulate the selection and print the amount of change owed back or an error message of why the selection is not possible (e.g. inventory out of stock, or not enough money deposited, or vending machine out of change).

restock <row> <column> <inventory>

Restock the product at location <row>, <column>, with <inventory> items. The max number of inventory for a particular product is limited to 5.

deposit <amount>

Deposit of <amount> change into the machine which is not available as change for subsequent purchases.

Hints and assumption:

1. An example command file VendingInput1.txt is provided that you can use to test your program and compare to the provided output file VendingOutput1.txt.

2. You might want to think about using the split method for Strings. This method will split a String that contains multiple words into an array where each element holds one of the words.

3. You can assume that the first command in the input file will always be initialize

4. You can assume that commands 2 through 17 will always be stock commands so the vending machine is populated with a Product object at each slot. Therefore you don't need to deal with null pointer errors.

Attachment:- Product.rar

Reference no: EM131585956

Questions Cloud

Summarize the decision of the us supreme court : Do you agree that the statute in question applies to computer-generated and computer-transmitted information?
How large of a loan can you take out : Assume you have been working at your first job since college for five years. how large of a loan can you take out?
What are your personal-professional biases : Biases can be personal or professional in nature. Confronting biases can help to overcome them. What are your personal/professional biases
Prepare a presentation for the board of sjl : Prepare a presentation for the Board of SJL which: explains the accounting treatment applied to each aircraft and the reasons for it
Simulate the use and maintenance of a vending machine : ITP 120 Project - Write a set of classes that work together to simulate the use and maintenance of a vending machine. Your program should read in an input
Calculate the firm quick ratio : Calculate the firm’s Quick Ratio
How the experience personally affected you : How experience personally affected you? How you plan to continue your participation in arts as either an audience member or creator of visual or performing art.
Violating the incompatible trinity as it maintains this peg : How does Hong Kong avoid violating the incompatible trinity as it maintains this peg?
Write an essay about a book : For these 2 distinct projects, imagine you are writing a series of short articles for a Bible Dictionary.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd