Assignment 49
import java.util.Scanner;
public class GenderGame
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String fName, lName, gender, marriage, prefix;
int age;
prefix = "";
marriage = "";
System.out.print("\nWhat is your gender (M or F)? ");
gender = keyboard.next();
System.out.print("First name: ");
fName = keyboard.next();
System.out.print("Last name: ");
lName = keyboard.next();
System.out.print("Age: ");
age = keyboard.nextInt();
if (gender.equals("F") && age >= 20)
{
System.out.print("\nAre you married, " +fName+ " (y or n)? ");
marriage = keyboard.next();
}
if (age >= 20)
{
fName = "";
if (gender.equals("F"))
{
if (marriage.equals("n"))
{
prefix = "Ms.";
}
if (marriage.equals("y"))
{
prefix = "Mrs.";
}
}
if (gender.equals("M"))
{
prefix = "Mr.";
}
}
System.out.println("\nThen I shall call you " +prefix+fName+ " " +lName+ ".");
}
}