Assignemnt #49 - Gender
Code
/// Name: Caelan Dorstad
/// Period: 6
/// Program Name: Gender
/// File Name: Gender.java
/// Date Finished: 10/23/2015
import java.util.Scanner;
public class Gender{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
String last, first, gender, married, m = "M" , f = "F" , y = "y" , n = "n";
int age;
System.out.print("What's your gender (M or F)?: ");
gender = keyboard.next();
System.out.print("First name: ");
first = keyboard.next();
System.out.print("Last name: ");
last = keyboard.next();
System.out.print("Age: ");
age = keyboard.nextInt();
System.out.println();
if ( gender.equals(f) && age > 20){
System.out.print("Are you married, " + first + " (y or n)?");
married = keyboard.next();
System.out.println();
if (married.equals(y)){
System.out.println("Then I shall call you Mrs. " + last);
}
else if (married.equals(n)){
System.out.println("Then I shall call you Ms. " + last);
}
}
else if (gender.equals(m) && age >20 ){
System.out.println("Then I shall call you Mr. " + last);
}
else if (gender.equals(m) && age < 20 ){
System.out.println("Then I shall call you "+ first + last);
}
else if (gender.equals(f) && age <20 ){
System.out.println("Then I shall call you "+ first + last);
}
}
}
Picture of the output