Consider a class DrinkMachine that models a vending machine. We will assume it only sells one...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
Verify DrinkMachine functionalities The MachineTest class seems designed to test various functionali... View the full answer
Related Book For
Statistics For Business Decision Making And Analysis
ISBN: 9780321890269
2nd Edition
Authors: Robert Stine, Dean Foster
Posted Date:
Students also viewed these programming questions
-
Write a program that extracts from a text all sentences that contain a particular word . We accept that the sentences are separated from each other by the character " . " and the words are separated...
-
Based on Exhibit 1, the expected future value of Bond I at maturity is closest to: A. 98.80. B. 103.74. C. 105.00. Lena Liecken is a senior bond analyst at Taurus Investment Management. Kristel...
-
Several executives of Computer Associates International, including former CEO Sanjay Kumar, pleaded guilty to providing fraudulent financial statements. The scheme was built around the backdating of...
-
Reconsider the loan application data in Table 7E.2. Set up the fraction nonconforming control chart for this process. Use the average sample size control limit approach. Plot the preliminary data in...
-
A patient ingests a radioactive isotope to treat a tumor. The isotope provides a dose of 0. 10 Gy. Which type of radiation will give the highest dose equivalent in Sv? A. Alpha particles B. Beta...
-
You have been asked to develop a work breakdown structure for a project. How should you go about accomplishing this? Should the WBS be time-phased, department-phased, division-phased, or some...
-
The management of real estate company is considering you as an external consulting group to outsource the task to develop a reliable predictive model to predict the selling price of the properties,...
-
Marquis Westbury invested $19,100 in the Ternton and Rainwater partnership for ownership equity of $119,000. Prior to the investment, equipment was revalued to a market value of $77,400 from a book...
-
the situations below. Develop a three-part perception checking strategy for each of 1. A roommate has not responded to your "Good morning" for three days in a row. This person is usually friendly. 2....
-
Your experience ( if any ) with cost and managerial accounting. If you do not have any experience, what are you interested the most in this class? How does this class relate to your life and work?
-
Who should regularly look for, identify, and dispute errors on your credit reports?
-
Three vertices (corners) of a right triangle are the points (1, 8), (5, 8 ), and (5, 1). Find the area of the triangle.
-
find out the NPV of below provided data Project NPV Name High Risk Avg. Risk Low Risk COMPANY $20,914 $35,329 $51,099 Paper Products $18,304 $32,734 $48,540 Timber Production $24,329 $38,720 $54,438...
-
The following table shows your stock positions at the beginning of the year, the dividends that each stock paid during the year, and the stock prices at the end of the year. What is your portfolio...
-
Cost Flows and Income Statement Floyds Tap Company manufacturers an extensive range of high-quality brass and chrome taps and has an excellent reputation for quality. The company is managed by John...
-
Cassandra Casey operates the Futuristic Antique Store. She maintains subsidiary ledgers for accounts payable and accounts receivable. She presents you with the following information for October 2019:...
-
The following output summarizes the fit of an analysis of covariance to the data in Exercise 35. The variable D denotes a dummy variable, with D = + for values colored green and 0 otherwise. (a) Does...
-
Match the description to the scatterplot. (a) Negative direction, linear, moderate variation around line (b) Positive direction, linear, small variation around line (c) No pattern. A plot of...
-
A construction company manages two large building projects. Both require about 50 employees with comparable skills. At a meeting, the site managers from the two projects got together to estimate the...
-
Explain how the control variate technique is implemented.
-
Suppose that in September 2013 a company takes a long position in a contract on May 2014 crude oil futures. It closes out its position in March 2014. The futures price (per barrel) is \($88.30\) when...
-
Use the technique discussed in Section9.4 to develop a GEE approach for zeroinflated Poisson model for count responses in longitudinal studies. Section9.4: 9.4 Marginal Models for Longitudinal Data...
Study smarter with the SolutionInn App