import java.util.*; public class Politics { public static void main(String[] args) { int age = 0; String party = " ", candidate = " "; boolean vote = false; Scanner keyboard = new Scanner(System.in); System.out.println("Are you old enough to vote?\n Please enter your age: "); age = keyboard.nextInt(); party = keyboard.nextLine(); // see page 95 if(18 <= age) { vote = true; System.out.println("You are old enough to vote."); } else if (18 > age) { vote = false; System.out.println("Sorry, you are not old enough to vote"); } else { System.out.print("Error"); System.exit(0); //exit program because of error } if (vote) { System.out.println("Are you voting Democrat (D) or Republican (R)?"); party = keyboard.nextLine(); if (party.equals("D")) { System.out.println("Are you voting for Obama (O) or Clinton (C)?"); candidate = keyboard.nextLine(); if (candidate.equals("O")) System.out.println("You are planning to vote for Obama."); else if (candidate.equals("C")) System.out.println("You are planning to vote for Clinton."); else { System.out.print("Error"); System.exit(0); //exit program because of error } } else if (party.equals("R")) { System.out.println("Are you voting for McCain (M) or Romney (R)?"); candidate = keyboard.nextLine(); if (candidate.equals("M")) System.out.println("You are planning to vote for McCain."); else if (candidate.equals("R")) System.out.println("You are planning to vote for Romney."); else { System.out.print("Error"); System.exit(0); //exit program because of error } } else { System.out.print("Error"); System.exit(0); //exit program because of error } } } }