import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.println("\nEnter Item name: ");
    Â
    String item_name = in.next();
    System.out.printf("Enter QTY of %s\n", item_name);
    int QTY = in.nextInt();
    System.out.println("Enter price per item of N$: \n");
    float item_price = in.nextFloat();
    Â
    System.out.println("Amount tendered N$: \n");
    float amount_tendered = in.nextFloat();
    float change = amount_tendered - (QTY * item_price);
    System.out.println(" Your change is N$: "+change);
    Â
    int n_20, n_10, n_5, n_1, n_50c, n_10c, n_5c;
    float rem = change % 20;
     n_20 = (int)change / 20;
     change = rem;
     rem = rem % 10;
    n_10 = (int) change / 10;
    Â
    change = rem;
    rem = rem % 5;
    n_5= (int) change / 5;
    Â
    change = rem;
    rem = rem % 1;
    n_1= (int) change / 1;
    Â
    change = rem;
    rem = rem % (float) 0.1;
    n_50c= (int) (change / 0.1);
    Â
    Â
    change = rem;
    rem = rem % (float) 0.5;
    n_10c= (int) (change / 0.5);
    Â
    change = rem;
    rem = rem % (float) 0.05;
    n_5c= (int) (change / 0.05);
    Â
    Â
    Â
    Â
System.out.printf("Disbursed as follows: %d x N$20; "
    + "%d x N$10; %d x N$5; %d x N$1; %d x "
    + "50c; %d x 10c; %d x 5c",n_20,n_10,n_5,n_1,n_50c,n_10c,n_5c);
    Â
    Â
    Â
    Â
    Â
  }
  Â
}
Comments
Leave a comment