Question: Please help me with the following tasks in Java, thanks! The goal of this lab is to prepare you to model classes after reading and

 Please help me with the following tasks in Java, thanks! The

goal of this lab is to prepare you to model classes after

reading and analysing a version of a customer brief who are looking

to hire you to implement their system. The vending machine is commonplace

Please help me with the following tasks in Java, thanks!

The goal of this lab is to prepare you to model classes after reading and analysing a version of a customer brief who are looking to hire you to implement their system. The vending machine is commonplace for students on campus to buy different food items. The gym at the university has purchased some vending machines and would need to imple- ment certain features to manage the inventory of the vending machines on campus. Each vending machine enables the students to buy one kind of item. This item could be chips, drinks, or cookies. Further, the vending machine also keeps track of the cost and quantity of each item. Note that the vending machine can hold a maximum of 10 drinks or chips or cookies at one time. A Vending machine has a power state which can be toggled ON and OFF using a single power button. That is, we are modelling a single toggle button as opposed to two separate on and off buttons. If a Vending machine is currently in the ON state then the following operations are possible: View the number of items and their cost for the particular vending machine. Add an item with their quantity and cost to the particular vending machine. If a Vending machine is currently in the OFF state, then the only operation that can be performed is to toggle the power to ON. The gym has hired you to perform the following tasks to manage the vending machines on campus. Task 2.1 Your first task is to model a Vending Machine class in Java. Please carefully read the above description to identify the class attributes and methods. You need to pay careful consideration to what parameters are used in your constructor and methods, along with exactly what setter, getter and other methods you make available. If a method is called which is not available (e.g., an attempt to view the number of items and their cost for the particular vending machine when the vending machine is off) then you should print out an error message to the screen. This will abort the current operation (i.e., method). The state of the vending machine will remain the same as before the operation was executed. Task 2.2 Another task is to extend the Vending Machine class so that each Vending Machine that is created has a unique automatically generated serial number (e.g., an integer). The serial number needs to be guaranteed unique. You cannot use a random number. The first available serial number is 1000. Negative serial numbers are not allowed. A serial number of O is not allowed. It should be possible to inspect (get) each individual Vending Machine serial number. However, It should be impossible to set the serial number of a TV. Hint: static is very useful to implement this efficiently. Task 2.3 Your task is to create a Test class and implement a main method to test your Vending Machine class implementation. Here you can reuse the implementation from the Lab 1. In your main method create an array that can hold 4 Vending Machine objects. Create all 4 Vending Machines. These Vending Machines will have the serial numbers 1000, 1001, 1002, and 1003. Place these four Vending Machines in increasing order of their serial numbers into entries 0-3 of the array (1000 in 0, 1001 in 1 etc). Write code that does the following. Set all the attributes for the Vending Machines. Here, use the implementation of the method to set the quantity of certain item in a vending machine to add more items in the given vending machine. Further, print the attributes of all the vending machines in the following manner: Vending-Machine Item-Name Quantity Cost 1000 Chips 9 5 1001 Drinks 7 3 1002 Cookies 2 1 Please note you can print the above output in any format. Task 2.4 Upon creation of a Vending Machine, a maximum quantity limit should be specified which should cap the maximum number items a vending machine should keep. The user should not be able to set the quantity that exceeds this limit. The maximum number of items should be 10 and if a user tries to set the quantity outside of this range then an exception should be used to abort the operation. You should use an IllegalArgumentException - this is a standard exception which indicates that a method has been passed an illegal or inappropriate argument. If you don't know exceptions, you should look it up in the Java API. Do a search for "java throw exceptions and use the official Oracle page. Also, look up the IllegalArgumentException. You should provide two constructors: A constructor that takes no parameters and sets the item quantity limit to 10 automati- cally. A constructor that takes a multiple parameter equal to the number of attributes of the class. Here, If the value of the quantity is below 1 i.e., negative or zero) or over 10 then an exception should be used to abort the construction of the instance. You should use an IllegalArgumentException

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!