hpilo

Chapter1_Ex2

Dec 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  /*
  4.         ==================================================
  5.             NoteBook chapter 1: language building stones
  6.  
  7.                     Ex2: Toast order
  8.         ==================================================
  9.  
  10.  */
  11.  
  12. public class MyProgram {
  13.  
  14.     public static void main(String[] args) {
  15.  
  16.         //variables
  17.         final int TOAST_PRICE=12;
  18.         final int CHEAP_EXTRA=2;
  19.         final int EXPENSIVE_EXTRA=3;
  20.         int totalCheap,totalExp;
  21.         Scanner s=new Scanner(System.in);
  22.         int totalPrice;
  23.  
  24.         //printing menu- optional: only for display
  25.         System.out.println("\n\t===================\n\t\tToast Menu\n\t===================");
  26.         System.out.println("Tost Price: "+TOAST_PRICE+"ILS\n");
  27.         System.out.print("cheap 2 ILS\t|\texpensive 3 ILS\n-----------------------------------\n");
  28.         System.out.print("tomatoes\t|\tExstra hard cheese\nolives\t\t|\tBulgarian cheese\n" +
  29.                          "mushrooms\t|\tcream cheese\ncorn\t\t|\thard cooked egg\n" +
  30.                          "onion\t\t|\teggplant\npeppers\t\t|\ttuna\n\n");
  31.  
  32.  
  33.         //user input
  34.         System.out.println("\nhow many cheap extras do you want? ");
  35.         totalCheap=s.nextInt();
  36.         System.out.println("how many Expensive extras?");
  37.         totalExp=s.nextInt();
  38.  
  39.         //calc price to pay
  40.         totalPrice=( TOAST_PRICE + (CHEAP_EXTRA*totalCheap) + (EXPENSIVE_EXTRA*totalExp) );
  41.         System.out.println("price to pay: "+ totalPrice+" ILS");
  42.        
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment