Answered step by step
Verified Expert Solution
Link Copied!

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 (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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

1. Describe the jury of executive opinion.

Answered: 1 week ago

Question

Define critical thinking and list its seven standards.

Answered: 1 week ago