Source of BooleanVariables.java


  2: import java.util.Scanner;

  4: /**
  5:  * Using boolean variables and "if" controls.
  6:  *
  7:  * @author Mark Young (A00000000)
  8:  */
  9: public class BooleanVariables {

 11:     public static void main(String[] args) {
 12:         Scanner kbd = new Scanner(System.in);

 14:         boolean senior, over55, disabled, eligibleForPension;
 15:         int age;

 17:         // introduce yourself
 18:         System.out.println("\n\n"
 19:                 + "I will check whether you are eligible for the pension.\n");

 21:         // get age
 22:         System.out.print("How old are you? ");
 23:         age = kbd.nextInt();
 24:         kbd.nextLine();

 26:         // check age categories
 27:         senior = age >= 65;
 28:         over55 = age >= 55;

 30:         // get disability status
 31:         System.out.print("You are diabled, true or false? ");
 32:         disabled = kbd.nextBoolean();
 33:         kbd.nextLine();

 35:         // blank line between input and output
 36:         System.out.println();

 38:         // echo back input
 39:         System.out.println("Your age: " + age);
 40:         System.out.println("Disabled: " + disabled);
 41:         System.out.println();

 43:         // calculate eligibility
 44:         eligibleForPension = senior || (disabled && over55);

 46:         // report result
 47:         if (eligibleForPension) {
 48:             System.out.println("You are eligible for the pension.");
 49:             System.out.println("For more information, visit "
 50:                     + "gov.ca/NoSuchPension.html");
 51:         } else {
 52:             System.out.println("You are not eligible for the pension.");
 53:             System.out.println("NEXT!");
 54:         }
 55:         System.out.println();
 56:     }

 58: }