public class Pension
2: import java.util.Scanner;
4: /**
5: * A program to test if the user is eligible for a (fake) GoC pension.
6: * Demonstrates nested if controls and boolean variables.
7: *
8: * @author Mark Young (A00000000)
9: */
10: public class Pension {
12: public static void main(String[] args) {
13: Scanner kbd = new Scanner(System.in);
14: int age;
15: boolean eligible;
16: String answer;
18: // get age from the user
19: System.out.print("What is your age? ");
20: age = kbd.nextInt();
21: kbd.nextLine();
23: // if 65+, then eligible
24: eligible = (age >= 65);
26: // if 55+, disabled, and live at home, then eligible
27: // (if already eligible, don't need to ask!)
28: if (age >= 55 && !eligible) {
29: // ask if disabled
30: System.out.print("Do you have a disability? ");
31: answer = kbd.nextLine().toLowerCase();
33: // if disabled, ask if on own
34: // (if not diabled, don't need to ask about living on own)
35: if (answer.startsWith("y")) {
36: System.out.print("Do you live on your own? ");
37: answer = kbd.nextLine().toLowerCase();
38: eligible = answer.startsWith("y");
39: }
40: }
42: // let eligible people know where to get more information
43: if (eligible) {
44: System.out.println("Go to www.gov.ca/BogusPension.html "
45: + "for more information.");
46: }
47: // and tell others they're not eligible
48: else {
49: System.out.println("Go away.");
50: }
51: }
53: }