Question: JAVA..The program should ask the user for a last name, a unit of measurement and a vegetable and then assemble these into a sentence. Use
JAVA..The program should ask the user for a last name, a unit of measurement and a vegetable and then assemble these into a sentence. Use the Scanner to read in user input.
Enter your last name: Zhang Enter a unit of measurement: meter Enter the name of a vegetable: pumpkin A tongue twister: Peter Zhang picked a meter of pickled pumpkins.
If spaces are entered at the beginning or ending of an answer, then remove them.
For the last name, the first character should be upper case and the rest lower case, now matter which case was used when entering the last name. Also, the user may enter multiple word last names, but for our assignment only the first character of the first word should be converted to upper case. The unit of measurement or the vegetable may be multiple words.
Write and call the following properCase method:
/** * This method returns the name with the first letter * in upper case and the rest lower case. Any spaces at * the beginning or ending are removed. Does not change * spaces in the middle of the string. * For multiple word names, only the first letter of the * first word should be upper case, all the rest lower case. * @param name a name that may be mixed case. * @return the name in proper case. */ public static String properCase(String name) { return null; //Write the code } Suggestion: Methods in the Scanner class (next() and nextLine()), String class (trim(), substring(), toUpperCase(), charAt(), etc.) and Character class may be helpful.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
