Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. Write a program that simulates a vending machine. The machine is assumed holds six items numbered 1 through 6, with prices RM1.25, RM0.75, RM0.90,
3. Write a program that simulates a vending machine. The machine is assumed holds six items numbered 1 through 6, with prices RM1.25, RM0.75, RM0.90, RM0.75, RM1.50 and RM0.75, respectively. The input for your program is an integer and floating-point number representing an item number and a sum of money, respectively. If the money is enough to buy any item, your program should print the balance: Thank you for buying item xxxx. Your change is RMxx.xx" If the money inserted is insufficient, then your program should alert the user that the amount of money is insufficient (show the missing amount) and cancel the transaction. The process should be repeated until the user decided to stop (see the example output below). Create methods at least for the following processes/operations: Getting the input Calculating the item's total price Displaying the result and related messages. The following display gives examples of output when the user uses this program (underlined texts are the input given by user) Available products: 1 : RM1.25 2 : RM0.75 4 : RM0.75 | 5 : RM1.50 3 : RM0.90 6 : RM0.75 Enter an item number and a sum of money: 31.00 Thank you for buying item 3. Your change is RM0.10 Buy another product (y) ? y Enter an item number and a sum of money: 6 0.25 Require RM0.50 more to buy product 6. Transaction cancelled. Buy another product (y) ? n Program finish. TESTING: Test the program for all product IDs, each with sufficient and insufficient payment. Also test the 'repeat' or 'not to repeat' options
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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