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

  What ways can vulnerable inmates be protected

What ways can vulnerable inmates be protected? Why are classification and housing assignments so critical to these populations?

  Give two different ijvm translations for the given java code

Give two different IJVM translations for the following Java statement: i = k + n + 5; Give the Java statement that produced the following IJVM code:

  Program buttons that implements a window with three button

Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter

  User interface menu using doubly linked lists

Each mNode defines the main menu item name, two links to its mNode neighbors (the previous and next mNode) and a link to its first submenu node.

  Write a method called add uneven arrays

Write a method called addUnevenArrays that takes two arrays, a and b, and returns a new array, c, with alength that is the maximum of the lengths of a and b. Each c[i] is the sum of the corresponding elementsof a and b if both elements exist.

  Create a class named pizza

Create a class named Pizza. This class should have three fields : a String for topping ( such as pepperoni, e.g.) , an integer for diameter in inches

  Java test program

Write a Java test program, all your code should be in the main method, that determines what type of organization is indicated by a web address. Your program should allow the user to enter a web address

  Describe one way in which one could apply java graphics

Describe one way in which one could apply Java graphics in education. Provide one example of such use to support your response. Analyze at least three commands that you would use in order to draw a bar chart.

  Create a complete java application

Create a complete Java application that meets these requirements and the program has an opening comments section (using block comments) with the file name, date, your name, and purpose of the program.

  Produce a java implementation of the gui

For your Assignment 2 Part 1 submission you are required to produce a Java implementation of the GUI for the Agriculture image viewer component of your overall Agriculture File Storing and Management (FSM) System.

  Determine when the application should stop looping display

Write an application that reads a series of pairs of numbers as follows: 1) product number 2) quantity sold - Create an application in java

  Adt for a two color double stack adt consists of two stacks

design an adt for a two color double stack adt that consists of two stacks one red and one blue and has its operations color coded versions of the regular stack adt operations.

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