If statement part 2 #49 (I wish I had somekind of special Prefix)
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name: Gender Game
/// File Name: GenderGame.java
/// Date Finished: 11/5/2015
import java.util.Scanner;
public class GenderGame {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String gender, firstName, lastName, isMarried, result;
int age;
System.out.print("What is your gender (M/F)? ");
gender = input.nextLine();
System.out.print("What is your first name? ");
firstName = input.nextLine();
System.out.print("What is your last name? ");
lastName = input.nextLine();
System.out.print("Are you married (Y/N)? ");
isMarried = input.nextLine();
System.out.print("How old are you? ");
age = input.nextInt();
if (age > 20) {
if (gender.equalsIgnoreCase("m")) {
result = "Mr. " + lastName;
} else {
if (isMarried.equalsIgnoreCase("y")) {
result = "Mrs. " + lastName;
} else {
result = "Ms. " + lastName;
}
}
} else {
result = firstName + " " + lastName;
}
System.out.println("\nThen I shall call you " + result + ".");
}
}
Picture of the output