Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 3: Logical and conditional expressions
- Ex3: check amount recommendation for wedding
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- final int BASE=250;
- final int BASE_FRIENDS=500;
- final int BASE_FAMILY=1000;
- final int EXTRA=50;
- final int YEARS=3;
- final int HOURS=1;
- boolean isFamily=false;
- float acquaintanceTime;
- float driveTime;
- int userInput;
- int checkAmount=0;
- Scanner s=new Scanner(System.in);
- //user input
- System.out.println("press the number accordanly: \n1. Family\n2. Close Friend \n3. Other ");
- System.out.print("your answer: ");
- userInput=s.nextInt();
- //init base amount according to user input
- switch (userInput){
- case 1:
- isFamily=true;
- System.out.println("recommendation: "+BASE_FAMILY+" NIS");
- break;
- case 2:
- checkAmount+=BASE_FRIENDS;
- break;
- case 3:
- checkAmount+=BASE;
- break;
- }
- //calc check amount according to user input (only for non family)
- if(!isFamily){
- //user input for how long they know the couple
- System.out.println("How many years do you know the couple?");
- acquaintanceTime=s.nextFloat();
- //if acquaintanceTime is more than 3 years- add 50 NIS
- if(acquaintanceTime>YEARS)
- checkAmount+=EXTRA;
- ////user input for how long it took to drive
- System.out.println("How many hours did you drive? ");
- driveTime=s.nextFloat();
- //if the drive time is more than 1 hour- sub 50 NIS
- if(driveTime>HOURS)
- checkAmount-=EXTRA;
- //display check amount recommendation
- System.out.println("recommendation: "+checkAmount+" NIS");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment