Assignment #49

Code

///Name: Mahima Choudhary
///Period: 6
///Project Name: GenderGame
///File Name: GenderGame.java
///Date Finished: 11/20/15

    import java.util.Scanner;

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

Picture of the output

YourInitials.html