Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92394670
  • Price:- $25

Priced at Now at $25, Verified Solution

Have any Question?


Related Questions in Java

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As