Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The problem for this Java program is in the attached file: 3.14 Program 3, part

ID: 3869732 • Letter: T

Question

The problem for this Java program is in the attached file:

3.14 Program 3, part 2, Silly string 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. Once you have the happy path implemented then consider various errors that may occur. For example, 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. * Greturn the name in proper case public static String properCase (String name) return null; //Write the code Suggestion: Methods in the Scanner class (next0 and nextLine0), String class (trim0, substring0, toUpperCase0, charAt0, etc.) and Character class may be helpful

Explanation / Answer

ProperCaseTest.java

import java.util.Scanner;

public class ProperCaseTest {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter your last name: ");

String lastName = scan.next();

System.out.print("Enter a unit of measure: ");

String measure = scan.next();

System.out.print("Enter a name of vegetable: ");

String veg = scan.next();

System.out.println("A tonque twister: Peter "+lastName+" picked a "+measure+" of pickle "+veg);

scan.nextLine();

System.out.println("Enter a name: ");

String name = scan.nextLine();

System.out.println("Proper Case: "+properCase(name));

}

public static String properCase(String name) {

name = name.trim();

char ch = name.charAt(0);

name = name.substring(1);

return String.valueOf(ch).toUpperCase()+name;

}

}

Output:

Enter your last name: Zhang
Enter a unit of measure: meter
Enter a name of vegetable: pampkin
A tonque twister: Peter Zhang picked a meter of pickle pampkin
Enter a name:
suresh murapaka
Proper Case: Suresh murapaka