Thursday, 5 September 2013

How do you get this code to allows the input of quarters and dollar bills?

How do you get this code to allows the input of quarters and dollar bills?

I was given an assignment where I have to use a java code given to me and
I have to allow the input of quarters and as well as the input to dollar
bills but I do not how to do that. So is there any way to do that. Here is
my code: package vendingmachine1;
import java.util.Scanner;
/**
*
* @author Link
*/
public class VendingMachine1
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
final int PENNIES_PER_DOLLAR=100;
final int PENNIES_PER_QUARTER=25;
System.out.print("Enter bill value(1 = $ 1 bill, 5 = $ 5 bill,etc.):");
int billValue = in.nextInt();
System.out.print("Enter the price in pennies:");
int itemPrice= in.nextInt();
// Compute change due
int changeDue = PENNIES_PER_DOLLAR*billValue-itemPrice;
int dollarCoins =changeDue/PENNIES_PER_DOLLAR;
changeDue = changeDue%PENNIES_PER_DOLLAR;
int quarters =changeDue/PENNIES_PER_QUARTER;
// Print change due
System.out.printf("Dollar coins:% 6d",dollarCoins);
System.out.println();
System.out.printf("Quarters: %6d",quarters);
System.out.println();
}
private static class of {
public of() {
}
}
}

No comments:

Post a Comment