Assignemnt #49 Gender Game
Code
Name: Iaroslav Titov
Period: 7
Project Name: GenderGame
File Name: GenderGame.java
Date: 10/21/2015
import java.util.Scanner;
import java.util.InputMismatchException;
public class GenderGame
{
public static void main(String[] args) {
try {
Scanner keyboard = new Scanner(System.in);
boolean isFemale, isMarried = false;
isFemale = false;
String fName, lName = "";
int age = 0;
System.out.print("What is your gender? M/F: ");
String input = keyboard.next();
switch (input) {
case "F":
isFemale = true;
break;
case "M":
isFemale = false;
break;
default:
System.out.println("WRONG INPUT!!!");
throw new InputMismatchException();
}
System.out.println();
System.out.print("First name: ");
fName = keyboard.next();
System.out.println();
System.out.print("Last name: ");
lName = keyboard.next();
System.out.println();
System.out.print("Age: ");
age = keyboard.nextInt();
if (isFemale && age >= 20) {
System.out.println();
System.out.print("Are you married, " + fName + "? Y/N: ");
input = keyboard.next();
System.out.println();
switch (input) {
case "Y":
System.out.println("Then I shall call you Mrs. " + lName+".");
break;
case "N":
System.out.println("Then I shall call you Ms. " + lName+".");
break;
default:
System.out.println("WRONG INPUT!!!");
throw new InputMismatchException();
}
} else if (age > 20 && !isFemale) System.out.println("Then I shall call you Mr. " + lName+".");
else System.out.println("Then I shall call you " + fName + " " + lName+".");
}
catch (InputMismatchException e)
{
System.out.println("END OF PROGRAM!!!");
}
}
}
Picture of the output