Answer:
Explanation:
The objective of this question is to write a java program for a vending machine.
/* This program finds out what amount the vending machine is going to dispense. A given item in the machine can cost between $0.25 and a dollar in five-cent increments (25, 30, 35, 40...90, 95 or 100), and the machine accepts only a dollar bill to pay for the item. */
// Compile: javac PP10. java
// Run: java PP10
// imported the scanner class from util package.
import java. util. Scanner;
//class declaration
public class PP10 {
// main method is defined here.
public static void main(String[] args)
{
// declaration of the variables.
Scanner keyboard=new Scanner (System.in):
//taking the string type input
int nl, 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 a dollar");
System.out.println ("so your change is ");
//the amount is first calculated.
amount=100-n1;
// quarter value is calculated
n2=amount/25;
// rest amount is get here.
amount=amount%25;
// dime value is calculated
n3-amount/10;
// rest amount is calculated
amount=amount%10;
// value of nickel is calculated here
n4=amount/5;
// rest amount is calculated
amount=amount%5;
//at last the number of pennies is get
n5=amount;
// Display output
System. out . println(n2+" quarters") :
System. out . println(n3+" dimes") ;
System. out . println(n4+" nickels") ;
System. out . println(n5+" pennies") ;
}
}
Output:
Enter the price of the item (from 20 cents to a dollar, in 5 - cents):
So, you bought an item for $0.45 and gave me one dollar; thus, your change is
2 quarters
0 dimes
1 nickel
0 pennies