Assignemnt #49
Code
/// Name: Connor Siri
/// Period: 7
/// Program Name: Gender
/// File Name: Gender.java
/// Date Finished: 10/19/2015
import java.util.Scanner;
class Gender{
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String Fn, Ln, mar, gen, n;
int age;
n = "";
System.out.print("What is your gender (M or F): ");
gen = keyboard.next();
System.out.print("First name: ");
Fn = keyboard.next();
System.out.print("Last name: ");
Ln = keyboard.next();
System.out.print("Age: ");
age = keyboard.nextInt();
if ( gen.equals("F"))
{
if ( age >= 20 )
{
Fn = "";
System.out.print("Are you married, " + Fn + " (y or n)? " );
mar = keyboard.next();
if (mar.equals("y"))
{
n = "Mrs. ";
}
if (mar.equals("n"))
{
n = "Ms. ";
}
}
}
else if (gen.equals("M"))
{
if ( age >= 20 )
{
Fn = "";
System.out.print("Are you married, " + Fn + " (y or n)? ");
mar = keyboard.next();
if (mar.equals("y"))
{
n = "Mr. ";
}
}
}
else
{
System.out.print("You didn't input right");
}
System.out.println("Then I shall call you " + n + "" + Fn + " " + Ln + ".");
}
}
Picture of the output