[java] kk

Viewer

  1. Scanner input = new Scanner(System.in);
  2.                  
  3.         double coffeeTot = 10;
  4.         double donutTot = 10;
  5.         double coffeePrice = 7.5;
  6.         double donutPrice = 4.25;
  7.         
  8.         double subtotal=0;
  9.         double discountedPrice = 0;
  10.         double total;
  11.  
  12.         System.out.println("Welcome to JAVA CAFE");
  13.         System.out.println("Please, enter order(#cups of coffee , and #dounuts)");
  14.         double coffeeCot = input.nextInt();
  15.         double donutCot = input.nextInt();
  16.  
  17.         if(coffeeCot<=coffeeTot && donutCot<=donutTot){
  18.             System.out.println("Are you student (true for yes, false for no )?");
  19.             boolean isStudent= input.nextBoolean();
  20.  
  21.             subtotal = (coffeeCot*coffeePrice)+ (donutCot*donutPrice);
  22.             
  23.             if(isStudent==true){
  24.                 discountedPrice = subtotal*0.10;
  25.                 total = subtotal-discountedPrice;
  26.  
  27.             }else {
  28.                     discountedPrice =0;
  29.                 total=subtotal;
  30.             }
  31.         System.out.println("---------------------------------------------------------");
  32.         System.out.printf("Item\t\t\tQuantity\t\tPrice\n");
  33.         System.out.printf("Coffe\t\t\t    %.2f\t\t\t%.2f\n",coffeeCot , (coffeeCot * coffeePrice));
  34.         System.out.printf("Donuts\t\t\t    %.2f\t\t\t%.2f\n" , donutCot , (donutCot * donutPrice));
  35.  
  36.         System.out.println("-----------------------------------------------------------");
  37.  
  38.         System.out.printf("Sub Total\t\t\t\t\t%.2f\n" , subtotal);
  39.         System.out.printf("Discount\t\t\t\t\t %.2f%n" , discountedPrice);
  40.  
  41.  
  42.         System.out.println("-----------------------------------------------------------");
  43.         System.out.printf("Total\t\t\t\t\t\t%.2f\n" , total);
  44.  
  45.         } else {
  46.  
  47.         System.out.println("Error:not enough cups and/or donuts");
  48.         
  49.         }
  50.  

Editor

You can edit this paste and save as new:


File Description
  • kk
  • Paste Code
  • 24 Feb-2021
  • 1.86 Kb
You can Share it: