Assignment #49 and Forty-Sixth Program

Code

        /// Name: Georgi Atanasov
        /// Period: 5
        /// Program Name: Gender Game
        /// File Name: GenderGame.java
        /// Date Finished: 12/1/2015
    
    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

Assignment 49