I cannot figure out how to write this program, can someone please help me?!
The purpose of this method is to practice manipulating St
rings.
Create a new program called Name.java. This program
will take a name string consisting of
EITHER a first name followed by a last name (nonstandar
d format) or a last name followed
by a comma then a first name (standard format). Ie
. “Joe Smith” vs. “Smith, Joe”. This
program will convert the string to standard format
if it is not already in standard format.
Write a method called hasComma that takes a name as
an argument and that returns a
boolean indicating whether it contains a comma. If i
t does, you can assume that it is in last
name first format. You can use the indexOf String m
ethod to help you.
Write a method called convertName that takes a name
as an argument. It should check
whether it contains a comma by calling your hasComma
method. If it does, it should just
return the string. If not, then it should assume th
at the name is in first name first format, and
it should return a new string that contains the name
converted to last name comma first
format. Uses charAt, length, substring, and indexOf
methods.
In your main program, loop, asking the user for a n
ame string. If the string is not blank, call
convertName and print the results. The loop terminat
es when the string is blank.
HINTS/SUGGESTIONS:
Use the charAt, length, substring, and indexOf Str
ing methods.
Use scanner for your input. To get the full line,
complete with spaces, use reader.nextLine()