Question: How do I write this program using java.io.* instead of java.util.Scanner???? Develop a Java program that computes which bills and coins will be given as
How do I write this program using java.io.*
instead of java.util.Scanner????
Develop a Java program that computes which bills and coins will be given as change for a sales transaction. Available bills are: $20 $10 $5 $1 Available coins are: quarter (25 cents) dime (10 cents) nickel (5 cents) penny (1 cent) Only print the actual bills and coins returned. Do not print unused denominations (for example, if no $10 bills are returned, do not print anything regarding $10 bills). Example: What is the total sales charge? 58.12 How much is the customer giving? 100.00 The change is: 2 $20 bills 1 $1 bill 3 quarters 1 dime 3 pennies
Here is the code using java.util.Scanner
mport java.util.Scanner;
public class changeMaker {
/**
*
*/
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int price;
int provided;
int change;
System.out.print("What is the total sales charge?");
price = (int) Math.round(keyboard.nextDouble() * 100);
System.out.print("How much is the customer giving?");
provided = (int) Math.round(keyboard.nextDouble() * 100);
if (provided > price) {
System.out.println("The change is:");
change = provided - price;
// Since you multiplied by 100 you have to divide by 2000 to get the number of twenties for change.
int twenties = change / 2000;
if (twenties > 0) { //if the change is less than $20 this will be a zero
change = change % 2000; // this resets the value of change to the remainder after the twenties are calculated but only if there was at least enough to make one twenty
System.out.println(twenties + " $20 bill(s)");
}
int tens = change / 1000;
if (tens > 0) {
change = change % 1000;
System.out.println(tens + " $10 bill(s)");
}
int fives = change / 500;
if (fives > 0) {
change = change % 500;
System.out.println(fives + " $5 bill(S)");
}
int ones = change / 100;
if (ones > 0) {
change = change % 100;
System.out.println(ones + " $1 bill(s)");
}
int quarters = change / 25;
if (quarters > 0) {
change = change % 25;
System.out.println(quarters + " quarter coin(s)");
}
int dimes = change / 10;
if (dimes > 0) {
change = change % 10;
System.out.println(dimes + " dime coin(s)");
}
int nickels = change / 5;
if (nickels > 0) {
change = change % 5;
System.out.println(nickels + " nickel coin(s)");
}
int pennies = change;
System.out.println(pennies + " penny coin(s)");
}
if (provided < price) { // this statement is saying that if the customer doesn't pay enough, it will tell the user
System.out.print("Not enough money!");
}
else if (provided == price) {
System.out.print("No change is necessary!");
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
