Question

Overview - Vending Machine For this project, we will simulate a vending machine where, for simplicity,...

Overview - Vending Machine

For this project, we will simulate a vending machine where, for simplicity, all of the items in the machine are the same price of $1.25

The vending machine can receive Nickels, Dimes, Quarters, and one dollar Bills.

The user can add money, ask for the product, ask for their money back, or walk away (exit).

The program will interact with the user and allow the following commands:

  • N - adds nickel
  • D - adds dime
  • Q - adds quarter
  • B - adds $1
  • R - returns money
  • P - dispenses product and returns change if the balance is enough to cover the cost
  • X – exit

Since in theory the user can buy two products, dispensing the product doesn’t end the program, exiting ends the program.

Sample Run

Item Cost: 1.25 Balance: 0.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): g

Invalid Coin or Bill or Command

Item Cost: 1.25 Balance: 0.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): p

Unable to dispense!

Item Cost: 1.25 Balance: 0.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): q

Item Cost: 1.25 Balance: 0.25

Enter Money(Q,D,N,B for Bill) or command (R, P, X): d

Item Cost: 1.25 Balance: 0.35

Enter Money(Q,D,N,B for Bill) or command (R, P, X): n

Item Cost: 1.25 Balance: 0.40

Enter Money(Q,D,N,B for Bill) or command (R, P, X): p

Unable to dispense!

Item Cost: 1.25 Balance: 0.40

Enter Money(Q,D,N,B for Bill) or command (R, P, X): b

Item Cost: 1.25 Balance: 1.40

Enter Money(Q,D,N,B for Bill) or command (R, P, X): p

Got Product with change: 0.15

Item Cost: 1.25 Balance: 0.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): b

Item Cost: 1.25 Balance: 1.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): b

Item Cost: 1.25 Balance: 2.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): p

Got Product with change: 0.75

Item Cost: 1.25 Balance: 0.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): b

Item Cost: 1.25 Balance: 1.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): d

Item Cost: 1.25 Balance: 1.10

Enter Money(Q,D,N,B for Bill) or command (R, P, X): d

Item Cost: 1.25 Balance: 1.20

Enter Money(Q,D,N,B for Bill) or command (R, P, X): d

Item Cost: 1.25 Balance: 1.30

Enter Money(Q,D,N,B for Bill) or command (R, P, X): p

Got Product with change: 0.05

Item Cost: 1.25 Balance: 0.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): b

Item Cost: 1.25 Balance: 1.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): d

Item Cost: 1.25 Balance: 1.10

Enter Money(Q,D,N,B for Bill) or command (R, P, X): d

Item Cost: 1.25 Balance: 1.20

Enter Money(Q,D,N,B for Bill) or command (R, P, X): p

Unable to dispense!

Item Cost: 1.25 Balance: 1.20

Enter Money(Q,D,N,B for Bill) or command (R, P, X): n

Item Cost: 1.25 Balance: 1.25

Enter Money(Q,D,N,B for Bill) or command (R, P, X): p

Got Product with change: 0.00

Item Cost: 1.25 Balance: 0.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): b

Item Cost: 1.25 Balance: 1.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): b

Item Cost: 1.25 Balance: 2.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): r

Money Returned: 2.00

Item Cost: 1.25 Balance: 0.00

Enter Money(Q,D,N,B for Bill) or command (R, P, X): x

Bye Bye!

Press any key to continue . . .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

balance = 0.00
  
while(True):
print("Item Cost: 1.25 Balance:{:,.2f}".format(balance))
key = input("Enter Money(Q,D,N,B for Bill) or command (R, P, X):").lower()
if(key == "x"):
print("Bye Bye!\nPress any key to continue . . .")
break
elif(key == "r"):
print("Money Returned:{:,.2f}".format(balance))
balance = 0.0
elif(key == "p"):
if(balance < 1.25):
print("Unable to dispense!")
else:
print("Got Product with change:{:,.2f}".format(round(balance - 1.25,2)))
balance = 0.0
elif(key == "q"):
balance += 0.25
elif(key == "d"):
balance += 0.1
elif(key == "n"):
balance += 0.05
elif(key == "b"):
balance += 1.0
else:
print("Invalid Coin or Bill or Command")
  
hope this is helpful, In info if x is pressed end the program ,but in sample output "press any key to continue.." ,there is little bit confusion, As of now it ends the program, for any modifications comment below

Add a comment
Know the answer?
Add Answer to:
Overview - Vending Machine For this project, we will simulate a vending machine where, for simplicity,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The California student chapter is co-sponsoring a tea vending machine with a heavily subsidized price of...

    The California student chapter is co-sponsoring a tea vending machine with a heavily subsidized price of 15 cents a cup. Design a Mealy FSM for the vending machine assuming the students can load nickels (input N) and dimes (input D), only one coin at a time. If the user tries to enter two coins at the same time, the vending machine would not allow it, i.e. it will stay in the same state. If the user pays more than 15...

  • C++ HW Question Your program will simulate a simple change maker for a vending machine. It...

    C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...

  • Criven products in a vending machine (Tahle and their respective prices (Table 2), develop VBA en...

    please help me ASAP ...l need a code yoour Criven products in a vending machine (Tahle and their respective prices (Table 2), develop VBA ende that would undertake the tollowing tasks after the customer clicks the 'purchase a producibttn: u. Tutheじustomer: i. Reive the custum' selcted product codu ii. Cunlim and display the customer's selected pruduct und product price. iii. Roccive the customer's moncy which may be input in onc or morc of the prescrihed denominations (Tahle 3). iv. Flag...

  • 1. Create a new multi-class Java program which implements a vending machine simulator which contains the...

    1. Create a new multi-class Java program which implements a vending machine simulator which contains the following functionality: A) At program startup, the vending machine is loaded with a variety of products in a variety of packaging for example soda/tonic/Coke in bottles, peanuts in bags, juice in cartons, etc. Also included is the cost of each item. The program should be designed to easily load a different set of products easily (for example, from a file). Also at program startup,...

  • ) Object-Oriented Design 7 Write a program that simulates a vending machine. Products can be purc...

    Write in java as simple as possible coding.. ) Object-Oriented Design 7 Write a program that simulates a vending machine. Products can be purchased by inserting coins with a value at least equal to the cost of the product. A user selects product from a list of available products, adds coins, and either gets the productor gets the coins returned. The coins are returned if insufficient money was supplied or if the product is sold out. The machine does not...

  • A customer want’s a vending machine that will accept Nickel and Dime and dispense gum or...

    A customer want’s a vending machine that will accept Nickel and Dime and dispense gum or candy. The gum pack cost 20₵ and the candy cost 15₵. When the user enters a coin in the slot it should decode the type of coin that has been entered and will displayed the total amount enter thus far in a seven segment display. If that amount is less than the item cost the system will tell the user that they have insufficient...

  • You are to write a program name Bank.java that maintains a list of records containing names...

    You are to write a program name Bank.java that maintains a list of records containing names and balance of customers. The program will prompt the user for a command, execute the command, then prompt the user for another command. The commands must be chosen from the following possibilities:           a    Show all records           r     Remove the current record           f     Change the first name in the current record           l     Change the last name in the current record           n    Add a new record           d   ...

  • 6.8.0 The Treasury bill rate is 2% and the market risk premium is 8%. Project Internal...

    6.8.0 The Treasury bill rate is 2% and the market risk premium is 8%. Project Internal Rate of Return, % 12 UOME Beta 1.00 0.00 3.00 0.40 2.60 a. What are the project costs of capital for new ventures with betas of 0.70 and 1.12? (Do not round intermediate calculations. Enter your answers as a percent rounded to 2 decimal places.) Beta Cost of Capital 0.7 1.12 b. Which of the capital investments shown above have positive (non-zero) NPV's? (You...

  • Below is the code for the class shoppingList, I need to enhance it to accomplish the...

    Below is the code for the class shoppingList, I need to enhance it to accomplish the challenge level as stated in the description above. public class ShoppingList {   private java.util.Scanner scan; private String[] list; private int counter; public ShoppingList() { scan = new java.util.Scanner(System.in); list = new String[10]; counter = 0; } public boolean checkDuplicate(String item) { for(int i = 0; i < counter; i++) { if (list[i].equals(item)) return true; } return false; } public void printList() { System.out.println("Your shopping...

  • Can you show the solution on the excel by showing the formulas? Tender Announcement of Vending...

    Can you show the solution on the excel by showing the formulas? Tender Announcement of Vending Machines at MetroBus Stops Istanbul Metropolitan Municipality (IMM) decided to rent out spots at MetroBus stops for vending machines to meet traveler demands and increase revenue. To ensure transparency and equal treatment, a tender was published on IMM's website. UniVEND saw this opportunity and gave the proposal to IMM. UniVEND's proposal was accepted and the company started to operate in all metrobus stops. Now...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT