Question: 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 (0)) 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
 Programming Exercise: Honorific Formatter Write a Java program that prompts the

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!