Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

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 spaceIndex.
Hint: Use the indexOf() method to find the position of the space.
Use spaceIndex 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.

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

Step: 3

blur-text-image

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

How do you add two harmonic motions having different frequencies?

Answered: 1 week ago

Question

What is the orientation toward time?

Answered: 1 week ago