Assignment #49: Gender Game
Code
/// Name: Kiran O'Farrell
/// Program Name: GenderConditionals
/// File Name: GenderConditionals.java
/// Date Completed: 11/28/15
import java.util.Scanner;
public class GenderConditionals {
public static void main (String[] args) {
Scanner keyboard = new Scanner(System.in);
String firstName, lastName, gender, married;
int age;
System.out.println("What is your first name?");
firstName = keyboard.next();
System.out.println("What is your last name?");
lastName = keyboard.next();
System.out.println("What is your gender, " + firstName + "?");
gender = keyboard.next();
System.out.println("How old are you, " + firstName + "?");
age = keyboard.nextInt();
if (age < 20) {
System.out.println("Then I shall call you " + firstName + " " + lastName + ".");
}
if (age > 20 && (gender.equals("male") || gender.equals("m"))) {
System.out.println("Then I shall call you Mr. " + firstName + " " + lastName + ".");
}
if (age > 20 && (gender.equals("female") || gender.equals("f"))) {
System.out.println("Are you married, " + firstName + "?");
married = keyboard.next();
if (married.equals("y") || married.equals("yes")) {
System.out.println("Then I shall call you Mrs. " + firstName + " " + lastName + ".");
}
if (married.equals("n") || married.equals("no")) {
System.out.println("Then I shall call you Ms. " + firstName + " " + lastName + ".");
}
}
}
}
Picture of the output