Input the amount of purchase which is
less than P100.00. Create a java program
that will calculate the change of P100.00
given by the customer with the
following breakdown:
P 50.00 - _______________;
P 20.00 - _______________;
P 10.00 - _______________;
P 5.00 - _______________;
P 1.00 - _______________;
Note: Purchases are all in pesos. No
centavos.
Formula Hint: Apply the concept of
modulus operator
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
Scanner sc= new Scanner(System.in);
int change=sc.nextInt();
if(change<=100){
int p50 = Math.round((int)change/50);
change=change%50;
int p20 = Math.round((int)change/20);
change=change%20;
int p10 = Math.round((int)change/10);
change=change%10;
int p5 = Math.round((int)change/5);
change=change%5;
int p1 = Math.round((int)change/1);
System.out.println("P50 " + p50);
System.out.println("P20: " + p20);
System.out.println("P10: " + p10);
System.out.println("P5: " + p5);
System.out.println("P1: " + p1);
}
else{
System.out.println("Input is must be less than equal to
100");
}
}
}
Get Answers For Free
Most questions answered within 1 hours.