Assignemnt #49: Gender Game
Code
/// Name: Cassie
/// Period: 6
/// Program Name: Gender Game
/// File Name: gengame.java
/// Date Finished: 11/20/2015
import java.util.Scanner;
class gengame
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String gender, firstName, lastName, married;
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 ( age > 20 && gender.equals ( "F" ) )
{
System.out.print( "Are you married, " + firstName + " (y or n)? ");
married = keyboard.next();
if ( married.equals ( "y" ) )
{
System.out.println( "Then I shall call you Mrs. " + lastName + "." );
}
else if ( married.equals ( "n" ) )
{
System.out.println( "Then I shall call you Ms. " + lastName + "." );
}
}
if ( age < 20 && gender.equals ( "F" ) )
{
System.out.println( "Then I shall call you Ms. " + lastName + "." );
}
if ( gender.equals ( "M") )
{
System.out.println( "Then I shall call you Mr. " + lastName + "." );
}
if ( gender.equals ( "M" ) && age < 20 )
{
System.out.println( "Then I shall call you " + firstName + " " + lastName + "." );
}
}
}
Picture of the output