Assignment 49

Code

  /// Name: Josh Bautista
  /// Period: 6
  /// Program Name: GenderGame
  /// File Name: GenderGame.java
  /// Date Finished: 12/10/2015
  
    import java.util.Scanner;

public class GenderGame
{
    public static void main( String[] args )
    {
        Scanner keyboard = new Scanner (System.in);
        
        String firstName, lastName, gender, choice;
        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 )
        {
            System.out.print(" Are you married, " + firstName + " (y or n )? ");
            choice = keyboard.next();
            if ( choice.equals("y") && gender.equals("M"))
            {
                System.out.print(" Then I shall call you Mr. " + lastName + " . ");
            }
            else if ( choice.equals("y") && gender.equals("F"))
            {
                System.out.print(" Then I shall call you Mrs. " + lastName + " . ");
            }
            else if ( choice.equals("n") && gender.equals("F"))
            {
                System.out.print(" Then I shall call you Ms. " + lastName + " .");
            }
            else if ( choice.equals("n") && gender.equals("M"))
            {
                System.out.print(" Then I shall call you " + firstName + lastName + " . ");
            }
        }
        else if ( age < 20 && gender.equals("M"))
        {
            System.out.print(" Then I shall call you " + firstName +  lastName + " . ");
        }
        else if ( age < 20 && gender.equals("F"))
        {
            System.out.print(" Then I shall call you " + firstName + lastName + " . ");
        }
    }
}
        
        

Picture of Output

Assignment 5