Question: Sample runs: User input is represented in bold . Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change



| Sample runs: User input is represented in bold. |
| Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): A -------------------------------- Candy Type Quantity -------------------------------- 1. Snickers 5 2. Twix 5 3. Milky Way 5 4. Almond Joy 5 5. Skittles 5 6. M&M's 5 Enter your choice (1 - 6): 1 You have chosen Snickers. Now Snickers has the quantity of 4 Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): A -------------------------------- Candy Type Quantity -------------------------------- 1. Snickers 4 2. Twix 5 3. Milky Way 5 4. Almond Joy 5 5. Skittles 5 6. M&M's 5 Enter your choice (1 - 6): 6 You have chosen M&M's. Now M&M's has the quantity of 4 Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): 2 Invalid Choice. Enter your menu choice (A - D): a -------------------------------- Candy Type Quantity -------------------------------- 1. Snickers 4 2. Twix 5 3. Milky Way 5 4. Almond Joy 5 5. Skittles 5 6. M&M's 4 Enter your choice (1 - 6): 5 You have chosen Skittles. Now Skittles has the quantity of 4 Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): b -------------------------------- Candy Type Quantity -------------------------------- 1. Snickers 4 2. Twix 5 3. Milky Way 5 4. Almond Joy 5 5. Skittles 4 6. M&M's 4 Enter the candy name to change: M&M's Enter the new candy name: Jelly Beans Jelly Beans replaces M&M's and has the quantity of 5 Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): c Enter the candy name: Skittles Skittles is restocked with 10 more Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): a -------------------------------- Candy Type Quantity -------------------------------- 1. Snickers 4 2. Twix 5 3. Milky Way 5 4. Almond Joy 5 5. Skittles 14 6. Jelly Beans 5 Enter your choice (1 - 6): 4 You have chosen Almond Joy. Now Almond Joy has the quantity of 4 Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): c Enter the candy name: M&M's M&M's is not on the list. Make a different selection. Enter the candy name to restock: Milky Way Milky Way is restocked with 10 more Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): J Invalid Choice. Enter your menu choice (A - D): A -------------------------------- Candy Type Quantity -------------------------------- 1. Snickers 4 2. Twix 5 3. Milky Way 15 4. Almond Joy 4 5. Skittles 14 6. Jelly Beans 5 Enter your choice (1 - 6): 4 You have chosen Almond Joy. Now Almond Joy has the quantity of 3 Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): b -------------------------------- Candy Type Quantity -------------------------------- 1. Snickers 4 2. Twix 5 3. Milky Way 15 4. Almond Joy 3 5. Skittles 14 6. Jelly Beans 5 Enter the candy name to change: M&M's M&M's is not on the list. Make a different selection. Enter the candy name to change: Snickers Enter the new candy name: Twizzlers Twizzlers replaces Snickers and has the quantity of 5 Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): a -------------------------------- Candy Type Quantity -------------------------------- 1. Twizzlers 5 2. Twix 5 3. Milky Way 15 4. Almond Joy 3 5. Skittles 14 6. Jelly Beans 5 Enter your choice (1 - 6): 1 You have chosen Twizzlers. Now Twizzlers has the quantity of 4 Candy Vending Machine Menu ---------------------------- A. Get a bag of candies - $ .70 B. Change Candy Selection C. Restock Candies D. Exit Enter your menu choice (A - D): d Total number of candies: 46
|
Design a Candy Machine class that can keep track of the type of candies and their quan ies. Use the following UML class diagram to design the class CandyMachine. Candy Machine SELECTION NUM final int- 6 -candy Names StringO -quantities in +getCandy Name (index int) String +setCandy Name (index int, newCandy String): void +getQuantity index int int +setQuantity(index int, es int): void +restock index int, numOfCandies int): void +decrementQuantity (index int boolean +total Quantity(): int +display Candies(): void tsearchIndexofCandyName(candyName String) int Program requirements and/or constraints: You will need to create a file to represent this class CandyMachinejava. The size of the arrays to be used wi ll be 6, and you can use a constant SELECTION NUM to express this. In your class, you declare it as public class CandyMachine private final int SELECTION NUM 6; The constructor of the CandyMachine class needs to initialize the content of two arrays, candyNames and quantities. They should have the following content Candy Type Quantity Milky Nay Almond Joy Skittles M&M Thus, the array candyNames contains Snickers Twix etc., and the array quantities contains 5 for all of them. Note that the array index starts with 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
