Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
- Ask the user for her/his full name using this prompt: System.out.print("Enter your full name: ");
- Print Hello, name! where name is the name that was entered.
- 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.
- 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 - Prompt the user for her/his age. Prompt with System.out.print("How old are you? ");
- Get the age
- 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 - 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started