Itp 120 project - write a set of classes that work together


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

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

Stock the vending machine at location , with a new product with

 

associated , , and

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

Select and dispense an item from the machine at location

, with

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

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

deposit

Deposit of 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

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Itp 120 project - write a set of classes that work together
Reference No:- TGS02381499

Now Priced at $25 (50% Discount)

Recommended (97%)

Rated (4.9/5)