hpilo

Chapter3_Logic_Ex3

Dec 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. import java.util.Scanner;
  2. /*  ==================================================
  3.       Chapter 3: Logical and conditional expressions
  4.  
  5.         Ex3: check amount recommendation for wedding
  6.     ===================================================
  7. */
  8.  
  9. public class MyProgram {
  10.     public static void main(String[] args) {
  11.  
  12.         //variables
  13.         final int BASE=250;
  14.         final int BASE_FRIENDS=500;
  15.         final int BASE_FAMILY=1000;
  16.         final int EXTRA=50;
  17.  
  18.         final int YEARS=3;
  19.         final int HOURS=1;
  20.  
  21.         boolean isFamily=false;
  22.  
  23.         float acquaintanceTime;
  24.         float driveTime;
  25.         int userInput;
  26.         int checkAmount=0;
  27.         Scanner s=new Scanner(System.in);
  28.  
  29.  
  30.         //user input
  31.         System.out.println("press the number accordanly:  \n1. Family\n2. Close Friend \n3. Other ");
  32.         System.out.print("your answer: ");
  33.         userInput=s.nextInt();
  34.  
  35.         //init base amount according to user input
  36.         switch (userInput){
  37.             case 1:
  38.                 isFamily=true;
  39.                 System.out.println("recommendation: "+BASE_FAMILY+" NIS");
  40.                 break;
  41.             case 2:
  42.                 checkAmount+=BASE_FRIENDS;
  43.                 break;
  44.             case 3:
  45.                 checkAmount+=BASE;
  46.                 break;
  47.         }
  48.  
  49.         //calc check amount according to user input (only for non family)
  50.         if(!isFamily){
  51.             //user input for how long they know the couple
  52.             System.out.println("How many years do you know the couple?");
  53.             acquaintanceTime=s.nextFloat();
  54.  
  55.             //if acquaintanceTime is more than 3 years- add 50 NIS
  56.             if(acquaintanceTime>YEARS)
  57.                 checkAmount+=EXTRA;
  58.  
  59.             ////user input for how long it took to drive
  60.             System.out.println("How many hours did you drive? ");
  61.             driveTime=s.nextFloat();
  62.  
  63.             //if the drive time is more than 1 hour- sub 50 NIS
  64.             if(driveTime>HOURS)
  65.                 checkAmount-=EXTRA;
  66.  
  67.             //display check amount recommendation
  68.             System.out.println("recommendation: "+checkAmount+" NIS");
  69.         }
  70.  
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment