Assignment #49
Code
///Name: Cody Swain
///Period: 6
///Project Name: NameGame
///File Name: NameGame.java
///Date: 10/26/15
import java.util.Scanner;
public class NameGame
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String gender, firstName, lastName, answer;
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();
if ( gender.equals("f") && age >= 20 )
{
System.out.print( "Are you married " + firstName + " (y or n)? ");
answer = keyboard.next();
if ( answer.equals("y") )
{
System.out.println( "Then I shall call you Mrs. " + lastName + "." );
}
else if ( answer.equals("n") )
{
System.out.println( "Then I shall call you Ms. " + lastName + "." );
}
}
else if ( gender.equals( "m" ) && age >= 20 )
{
System.out.println( "Then I shall call you Mr. " + lastName + "." );
}
else if ( age < 20 )
{
System.out.println( "Then I shall call you " + firstName + " " + lastName + "." );
}
}
}
Picture of the output