Assignment #49 and Gender Game
Code
/// Name: Brendan Baird
/// Period: 6
/// Program Name: Gender Game
/// File Name: GenderGame.java
/// Date Finished: 10/22/2015
import java.util.Scanner;
public class GenderGame
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String gender, firstname, lastname;
String married = "";
String formalname = "";
int age;
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();
System.out.println();
if ( gender == "F" && age >= 20 )
{
System.out.println("Are you married, " + firstname + " (n or y)? ");
married = keyboard.next();
System.out.println();
if ( married == "y" )
formalname = "Mrs. " + lastname;
else
formalname = "Ms. " + lastname;
}
else if ( gender == "M" && age >= 20)
formalname = "Mr. " + lastname;
else
formalname = firstname + " " + lastname;
System.out.println("Then I shall call you " + formalname + ".");
}
}
Picture of the output