Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider a class DrinkMachine that models a vending machine. We will assume it only sells one type of drink. It is constructed with a
Consider a class DrinkMachine that models a vending machine. We will assume it only sells one type of drink. It is constructed with a maximum capacity (number of drinks it can hold). There is a method insertCoin to put money in the machine, and at any time the machine has a balance representing the amount of money inserted but not spent. If the balance is greater than or equal to the drink price, AND if there is at least one drink in the machine, the dispense() method decreases the number of drinks by 1 and sets the balance to zero. If the balance was greater than the drink price, the excess goes into the clin return. On the other hand, if the machine is empty. or the balance is less than the drink price, the dispense() method just transfers the balance to the coin return. Detailed specification: A constructor Drink Machine(int givenCapacity), constructs a machine that can hold the given number of drinks but initially contains no drinks and has a balance of zero. . A public integer constant PRICE with value 150 cents, representing the drink price A method insertCoin(int value) that adds the given amount, in cents, to the balance. . A method restock(int howMany) that adds the given number of drinks to the machine without going over the maximum capacity A method getCount() that returns the number of drinks in the machine . A method getBalance() that returns the current balance, in cents Canvas i + A method getCount() that returns the number of drinks in the machine A method getBalance() that returns the current balance, in cents A method getCoinReturn() that returns the amount of money, in cents, currently in the coin return tray A method clearCoin Return() that sets the amount in the coin return to zero A method dispense() that works as follows: If the balance is greater than or equal to the drink price, and if there is at least one drink in the machine, the dispense() method decreases the number of drinks by 1 and sets the balance to zero. If the balance was greater than the drink price, the excess goes into the coin return. On the other hand, if the machine is empty, or the balance is less than the drink price, the dispense() method just transfers the balance to the coin return. a) (10 pts) CLICK TO EXPAND/MINIMIZE PART A b) (25 pts) CLICK TO EXPAND/MINIMIZE PART B CLICK TO EXPAND/MINIMIZE PART A Write a class MachineTest with a main method that tests the Drink Machine class above for the following cases: For a machine containing no drinks, after calling insertCoin(100) twice, the balance is 200. Then after calling dispense() the balance is zero and the coin return is 200 For a machine that contains 9 drinks, has a balance of 100, and has 50 cents sitting in the coin return, after calling dispense() it still contains 9 drinks and has 150 in the coin return In each case print out the actual value returned by the appropriate accessor method, and print out the correct value that you expect. You can just print the numbers, no labels or explanations are required. You can write "SOP" to abbreviate "System.out.println". DO NOT USE JUNIT, this is just a main method. public class MachineTest { { public static void main(String[] args) } } CLICK TO EXPAND/MINIMIZE PART B Write a complete implementation of the DrinkMachine class described above. You can copy and paste the following template: public public class DrinkMachine public static final int PRICE = 150; public DrinkMachine (int givenCapacity) {. } public void insertCoin (int value) { } public void restock (int howMany) { } public int getCount() { } public int getBalance() { } public int getCoinReturn() { } public int getBalance() { } public int getCoinReturn() { } public void clearCoinReturn() { } public void dispense() { } Edit Format Table 12pt Paragraph BI U AY 2Y TRY B
Step by Step Solution
★★★★★
3.50 Rating (150 Votes )
There are 3 Steps involved in it
Step: 1
Verify DrinkMachine functionalities The MachineTest class seems designed to test various functionali...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started