Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THIS IS FOR JAVA In this assignment you will design a program to give customers

ID: 3673371 • Letter: T

Question

THIS IS FOR JAVA

In this assignment you will design a program to give customers the correct change.

Here are the parameters:

1) Coins to use and their values: Half Dollars (50) Quarter Dollars (25) Dimes (10) Nickels (5) Pennies (1)

The user will enter a number between 1 and 99. If the number is outside of that range, you will inform the user and terminate the program.

You will use as few coins as possible. For example, if the user enters "50", you will give the answer as "One Half Dollar" and not "5 Dimes" or "50 Pennies".

You will loop through each coin denomination, with the possible exception of the penny.

Here is a hint: If the number is 99, then subtract 50 from the number using a loop. This leaves 49, with one half dollar used.

Next, subtract 25 from the total using a loop. This leaves 24, with one quarter used

Next, subtract 10 cents from the total in a loop. This will leave 4 cents, with two dimes used.

Finally record the four pennies left over.

The output should read something like: "You have one half dollar, one quarter, two dimes, and four pennies".

Explanation / Answer

program:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author MDR
*/
import java.io.*;
import java.util.Scanner;
public class BillChange {
public static void main(String[] args)
{
double[] bills=new double[5];
double[] paid=new double[5];
int dollar,quater,dimes,nickels,pinnies,c;
double change;
Scanner scan=new Scanner(System.in);
for(int i=0;i<5;i++)
{
System.out.println("Enter Bill"+(i+1)+":");
bills[i]=scan.nextDouble();
}
for(int i=0;i<5;i++)
{
System.out.println("Enter Bill"+(i+1)+" paid:");
paid[i]=scan.nextDouble();
}
for(int i=0;i<5;i++)
{
System.out.println("Bill"+(i+1)+":");
  
change=paid[i]-bills[i];

c=(int)(change*100);
//c=change.intValue()
//c=Integer.parseInt(change+"");
  
System.out.println("Dollars:"+c/100);
c=c%100;
  
System.out.println("Quarters:"+c/25);
c=c%25;
  
  
System.out.println("Dimes:"+c/10);
c=c%10;
  
System.out.println("Nickels:"+c/5);
c=c%5;
  
System.out.println("pennies:"+c);
  
  
}
}
  
}

output:

run:
Enter Bill1:
23.56
Enter Bill2:
54.25
Enter Bill3:
65.25
Enter Bill4:
254.36
Enter Bill5:
269
Enter Bill1 paid:
40
Enter Bill2 paid:
60
Enter Bill3 paid:
100
Enter Bill4 paid:
500
Enter Bill5 paid:
1000
Bill1:
Dollars:16
Quarters:1
Dimes:1
Nickels:1
pennies:4
Bill2:
Dollars:5
Quarters:3
Dimes:0
Nickels:0
pennies:0
Bill3:
Dollars:34
Quarters:3
Dimes:0
Nickels:0
pennies:0
Bill4:
Dollars:245
Quarters:2
Dimes:1
Nickels:0
pennies:4
Bill5:
Dollars:731
Quarters:0
Dimes:0
Nickels:0
pennies:0
BUILD SUCCESSFUL (total time: 47 seconds)