Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming Exercise: Honorific Formatter Write a Java program that prompts the user for a single string, which represents a person's name: first name and last
Programming Exercise: Honorific Formatter
Write a Java program that prompts the user for a single string, which represents a
person's name: first name and last name.
The program should:
Accept all input from the console using the Scanner.nextLine method.
Store the input to a single String object named fullName.
Determine the position of the space or separating the first and last name
and assign the position to an integer variable named spacelndex.
Hint: Use the indexOf method to find the position of the space.
Use spacelndex to extract the substrings of the first name and last name, assigning
each to String objects named firstName and lastName.
Hint: Use the substring method to extract a substring from the original
string.
Extract the first character at position zero from firstName and assign it to a char
variable named initial.
Hint: Use the charAt method to extract the character from the string.
Format the data obtained into an honorific for a doctor.
Use string concatenation or System.out.printf to produce the output.
Write Java code to implement the above requirements. Ensure that the program
follows the given instructions precisely and produces the expected output format.
Once you've completed the implementation, test your program with different inputs to
verify its correctness and ensure it produces the expected output format.
OUTPUT:
Enter name: Alice Johnson
Honorific: Dr A Johnson
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