Assignemnt #49: GenderGame
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: GenderGame
/// File Name: GenderGame.java
/// Date Finished: 11/6/2015
import java.util.Scanner;
public class GenderGame
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String gender, fname, lname, mar;
int age;
System.out.print("What 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 (age >= 20 && gender.equals("F"))
{
System.out.print("Are you married? (yes or no): ");
mar = keyboard.next();
System.out.println();
if (mar.equals("yes"))
System.out.println("I shall call you Mrs. " + lname + ".");
if (mar.equals("no"))
System.out.println("I shall call you Ms. " + lname + ".");
}
else
{
if (gender.equals("M") && age >= 20)
{
System.out.println();
System.out.println("I shall call you Mr. " + lname + ".");
}
if ((gender.equals("M") && age < 20) || (gender.equals("F") && age < 20))
{
System.out.println();
System.out.println("I shall call you " + fname + " " + lname + ".");
}
}
}
}
Picture of the output