Question: Write an application called IfPractice. It will have a main method. There is no starter code file. In the main method: do the following: Ask

Write an application called IfPractice. It will have a main method. There is no starter code file.

In the main method: do the following:

  1. Ask the user for her/his full name using this prompt: System.out.print("Enter your full name: ");
  2. Print Hello, name! where name is the name that was entered.
  3. Get just the first name. If the full name has a space, then the substring before the first space is the first name; otherwise, take the full name as the first name.
  4. Print: I think I will call you nickname. where nickname is the nickname in the table below.
    First Name Nickname
    James or james Jim
    Robert or robert Bobby
    Ashwani or ashwani Ash
    Any other name Buddy
  5. Prompt the user for her/his age. Prompt with System.out.print("How old are you? ");
  6. Get the age
  7. Based on the age, print one of the messages in the table followed by a comma, a space, and the nickname followed by a period. Example: You are a child, Jim.
    This age and over Under Message
    0 18 You are a child
    18 21 You can vote, but you can not drink
    21 65 You are a full adult
    65 You can get Social Security
  8. Print Goodbye, name! where name is the original name that was entered.

Notes:

  • Use the proper if structure.
  • Do not use do nothing if or else clauses.
  • Do not do unnecessary tests in the if clause. For example this is incorrect: if (age < 18) . . . else if (age >= 18 && age < 21) Leave out the age >= 18. It HAS to be true because you have just determined that age < 18 is false.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!