Question

In: Computer Science

Write a program that determines the change to be dispensed from a vending machine. An item...

Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and 1 dollar, in 5-cents increments (25, 30, 35, . . . 90, 95, or 100), and the machine accepts only a single dollar bill to pay for the item. (Explain with algorithms if you can please!)

Solutions

Expert Solution

Executable code:

import java.util.Scanner;
public class VendingMachine{
public static void main(String args[])
{
Scanner keyboard=new Scanner(System.in);
int n1,amount,n2,n3,n4,n5;
System.out.println("Enter price of item (from 20 cents to a dollar, in 5-cents):");
n1=keyboard.nextInt();
System.out.println("You bought an item for "+n1+" cents and gave me adollar");
System.out.println("So your change id");
amount=100-n1;
n2=amount/25;
amount=amount%25;
n3=amount/10;
amount=amount%10;
n4=amount/5;
amount=amount%5;
n5=amount;
System.out.println(n2+" quarters");
System.out.println(n3+" domes");
System.out.println(n4+" nickels");
System.out.println(n5+" pennies");
}
}

Output:


Related Solutions

1-You want to dispense an item from the vending machine. An item in the machine can...
1-You want to dispense an item from the vending machine. An item in the machine can cost between 25 cents and a dollar, in 5 cent increments (25,30,35,,40,45......,90,95,100) and the machine accepts only a single dollar bill to pay for the item. Write a java class called ChangeMaker that will determine the change to be dispensed from a vending machine. Use the following UML diagram. ChangeMaker        Attributes    private double money    private int numberOfQuarters    private int...
The amount of coffee dispensed by a drink vending machine is normally distributed with a mean...
The amount of coffee dispensed by a drink vending machine is normally distributed with a mean of 12.1 oz. What is the probability that a randomly selected cup of coffee has more than 12.8 oz? Assume that the standard deviation for all drink vending machines is 0.38
Using a vending machine requires instructions from the person buying an item and the machine dispensing...
Using a vending machine requires instructions from the person buying an item and the machine dispensing the item. Using terms and concepts learned this week, discuss the following activities. What actions by either the person buying an item or the vending machine would you describe as a privilege or non-privileged instructions? Why? Relate memory management concepts (virtual, real) to the operation of the vending machine. Relate processes and threads to the operation of the vending machine. Directly address each question...
7.) The target temperature for a hot beverage the moment it is dispensed from a vending...
7.) The target temperature for a hot beverage the moment it is dispensed from a vending machine is 173◦F. A sample of 15 randomly selected servings from a newly manufactured vending machine gave a mean temperature of 170◦F with a standard deviation of 6.4◦F. Using our 6-step process, test that the mean tem- perature dispensed from this new machine differs from the target temperature.
3. Write a program that simulates a vending machine.   The user will be prompted to enter...
3. Write a program that simulates a vending machine.   The user will be prompted to enter a number then a letter. As part of the prompt you must display a message to indicate the number and letter, along with the possible choices. That is, what selections will give user which item.   If the user enters a number or a letter that is not valid, then display the message “Bad Entry” and end the program. (100 pts) Selections with messages. 1a...
Write a program that simulates a vending machine. The machine holds six snack items labeled them...
Write a program that simulates a vending machine. The machine holds six snack items labeled them 1 through 6. The program should initially display a menu of items along with their prices: Vending Machine 1. Roasted Almonds --> $1.25 2. Pretzels --> $1.75 3. Chewing Gum --> $0.90 4. Mints --> $0.75 5. Chocolate bar --> $1.50 6. Cookies --> $2.00 The program then should ask the user to enter the item to purchase along with a sum of money....
Write a C++ program that reads a string from a text file and determines if the...
Write a C++ program that reads a string from a text file and determines if the string is a palindrome or not using stacks and queue
A random sample of 36 cups of soda dispensed from the old soda machine in the...
A random sample of 36 cups of soda dispensed from the old soda machine in the lobby had a mean amount of soda od 7 ounces. Assume that the population standard deviation is 1 ounce. a. Find the best point estimate of the amount of soda dispensed. b. Construct and interpret a 95% confidence interval for the true population mean amount of soda dispensed from the old soda machine in the lobby.
Exercise 7: Name that Shape Write a program that determines the name of a shape from...
Exercise 7: Name that Shape Write a program that determines the name of a shape from its number of sides. Read the number of sides from the user and then report the appropriate name as part of a meaningful message. Your program should support shapes with anywhere from 3 up to (and including) 10 sides. If a number of sides outside of this range is entered then your program should display an appropriate error message. language use : python
4. Write a program that reads all numbers from a file and determines the highest and...
4. Write a program that reads all numbers from a file and determines the highest and lowest numbers. You must NOT use arrays to solve this problem! Write functions where appropriate. Programming language should be C
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT