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
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.
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....
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
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.
Sam is considering purchase of a vending machine to sell sodas. The cost of the vending...
Sam is considering purchase of a vending machine to sell sodas. The cost of the vending machine is $3,400. Sam estimates that the vending machine will last for five years and will provide net income of $800 each year for its lifetime. a. If Sam pays $3,400 for the vending machine today, what is its net present value at 7%? Should Sam purchase the vending machine? b. If Sam pays $3,400 for the vending machine today, what is its net...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar date after January 1, 1900, which was a Monday. This program will need to account for leap years, which occur in every year that is divisible by 4, except for years that are divisible by 100 but are not divisible by 400. For example, 1900 was not a leap year, but 2000 was a leap year.
Write a program that determines a student’s grade. The program will read three types of scores...
Write a program that determines a student’s grade. The program will read three types of scores (quiz, mid-term, and final scores) and determine the grade based on the following rules: -if the average score =90% =>grade=A -if the average score >= 70% and <90% => grade=B -if the average score>=50% and <70% =>grade=C -if the average score<50% =>grade=F Using Switch Statement Need to code to be simple to understand. No pointers should be used
Coding Java Vending machine Lab
Given two integers as user inputs that represent the number of drinks to buy and the number of bottles to restock, create a VendingMachine object that performs the following operations:Purchases input number of drinksRestocks input number of bottlesReports inventoryThe VendingMachine is found in VendingMachine.java. A VendingMachine's initial inventory is 20 drinks.Ex: If the input is:5 2the output is:Inventory: 17 bottles import java.util.Scanner; public class LabProgram {    public static void main(String[] args) {       Scanner scnr = new Scanner(System.in);              /* Type your code here. */            } }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT