Assignemnt #49 and GenderGame
Code
/// name: Leila Ordukhani
/// period: 6
/// program name: Thirty-Eight Program
/// file name: GenderGame.java
/// date finished: 11/6/15
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 >= 18 )
{
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 >= 18)
formalname = "Mr. " + lastname;
else
formalname = firstname + " " + lastname;
System.out.println("Then I shall call you " + formalname + ".");
}
}
Picture of the output