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

  Write a program that prompts the user to enter an integer

Write a program that prompts the user to enter an integer. If the number is a multiple of 3, print "Multiple of 3."Otherwise, print "Not Multiple of 3." Here are the sample runs:

  Create a program that holds a simple address book

Create a class HashTable which implements HashTableInterface with buckets. You can use an array of linked lists(of Person objects).You may add any other methods you think are necessary.

  What is the difference between iterator and enumeration

What is the difference between Iterator and Enumeration

  Analyze a task and describe it succinctly

Programming the Familiar Good programmers are able to analyze a task and describe it succinctly, accurately, and unambiguously. Even tasks that you perform without much thought are surprisingly complex when you stop and consider all of their compo..

  Write a java applet that views staff information

Write a Java applet that views, inserts, and updates staff information stored in a table Staff in an Oracle Database. The View button displays a record with a specified ID

  Create a class called author

Create a class called Author is designed as follows: Three private instance variables: name (String), email (String), and gender (char of either ‘m' or ‘f'); One constructor to initialize the name, email and gender with the given values

  Including four sets of quadruplet andsevwn sets of triplets

Mrs. Bernard Scheinberg of Austria had sixty-nine children. Including four sets of quadruplet, sevwn sets of triplets, and sixten of twins. after Mrs. scheinberg died at the age of 56, her husband remarried. during his remaining years, he fathered an..

  Create a tic-tac-toe

create a tic-tac-toe

  Print member method and a separate println statement

Use the print member method and a separate println statement to output courseStudentss data -

  Create a software artifact by applying the methodologies

Create a software artifact by applying the methodologies of advanced object- oriented programming to a requirements speciation. Select and apply a design pattern from one of the major design patterns to solve a given problem.

  Write a program that plots a bar chart for comparing mtbfs

Write a program that plots a bar chart for comparing the MTBFs of different elevator models. The data to be displayed is prepared in a file: Each line consists of the model's letter and the MTBF that has been measured for that file.

  Write a program using jdbc for getting personal information

Write Java application program to change the basic = basic + 500 of all the employees whose age is greater then 40 from employee table then display how many record updated

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