Assignemnt #49 and Gender Game
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: Gender Game
///File Name: GenderGame
///Date Finished: 10/27/15
import java.util.Scanner;
public class GenderGame
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String gender, marriage, firstName, lastName;
int age;
boolean male, female, yesMarriage, noMarriage;
System.out.print( "What is your gender (M or F): " );
gender = keyboard.next();
male = gender.equals( "M" );
female = gender.equals( "F" );
System.out.print( "First name: " );
firstName = keyboard.next();
System.out.print( "Last name: " );
lastName = keyboard.next();
System.out.print( "Age: " );
age = keyboard.nextInt();
System.out.print( "Are you married, " + firstName + " (y or n)? " );
marriage = keyboard.next();
yesMarriage = marriage.equals( "y" );
noMarriage = marriage.equals( "n" );
if( male && age < 20 )
{
System.out.println( "Then I shall call you " + firstName + " " + lastName + "." );
}
if( male && age >= 20 )
{
System.out.println( "Then I shall call you Mr. " + lastName + "." );
}
if( female && age < 20 )
{
System.out.println( "Then I shall call you " + firstName + " " + lastName + "." );
}
if( female && age >= 20 && yesMarriage )
{
System.out.println( "Then I shall call you Mrs. " + lastName + "." );
}
if( female && age >= 20 && noMarriage )
{
System.out.println( "Then I shall call you Ms. " + lastName + "." );
}
}
}
Picture of the output