Assignment #49 and GenderGame
Code
/// Name: Jason Kim
/// Period: 7
/// Program Name: GenderGame
/// File Name: GenderGame.java
/// Date Finished:10/19/15
import java.util.Scanner;
public class GenderGame
{
public static void main(String[] args)
{
String gender, firstName, lastName, name, married;
int age;
Boolean condition1, condition2;
Scanner keyboard = new Scanner(System.in);
System.out.print("What is your gender ( M or F ): ");
gender = keyboard.next();
System.out.print("First name: ");
firstName = keyboard.next();
System.out.print("Last name: ");
lastName = keyboard.next();
System.out.print("Age: ");
age = keyboard.nextInt();
condition1 = (age >= 20) && (gender.equals("F"));
condition2 = (age >= 20) && (gender.equals("M"));
if ( condition1 )
{
System.out.print("\nAre you married, " + firstName + " (y or n)? ");
married = keyboard.next();
if(married.equals("y"))
{
name = "Mrs. " + lastName;
System.out.println("\nThen I shall call you " + name + ".");
}
if(married.equals("n"))
{
name = "Ms. " + lastName;
System.out.println("\nThen I shall call you " + name + ".");
}
}
if ( age < 20)
{
name = firstName + " " + lastName;
System.out.println("\nThen I shall call you " + name + ".");
}
if ( condition2)
{
name = "Mr. " + lastName;
System.out.println("\nThen I shall call you " + name + ".");
}
}
}
Picture of the output