Question: java programming y Notifications - soph... Content MET CS 520 (Spring 1 20...) Bb https://learn-us-east-1-p... 1 Yuzu: Absolute Java (Su... Java Certification C Create a



java programming
y Notifications - soph... Content MET CS 520 (Spring 1 20...) Bb https://learn-us-east-1-p... 1 Yuzu: Absolute Java (Su... Java Certification C Create a package named cs520.hw3.part1. Within this package, create a class called StringTest and implement the following functionality in its main() method: a. Using Scanner, ask the user to his or her name, age and city all at once in the format Name, Age, City (see sample input below) and read the value as a String variable called input using Scanner's nextLine() method. b. Remove any spaces that were entered at the beginning or at the end of the input using String's trim() method. Recall that trim() is a non-destructive method, so the original string will not be changed; you will need to replace the value of input with the trimmed version. c. Find the position of the first comma in input using the indexOf() method and assign it to an int variable called index 1. Using index1, extract the name part of the input using the substring() method and assign it to a new variable called name. d. Print the name value and the length of name to the console. Example: "Name; John (length: 4)" e. Find the position of the second comma in input using the indexOf() method and assign its value to a new int variable called index2. (Hint: use indexOf() with index1 + 1 as the second argument.) f. Using index1 and index2, extract the age part of input using the substring() method and assign it to a new variable called ageString. g. Convert ageString to an int and store the integer in a new variable called age. g. Convert ageString to an int and store the integer in a new variable called age. h. Print the age value, as well as what the user's age will be 10 years from now, to the console. Example: "Age 25", "In 10 years you will be 35" i. Extract the city using index2 and the substring() method and assign it to a new variable called city. Display city to the console as well as its length. Example: "City: Boston (length: 6)" j. Place all of the code within the main() method in a try-catch block to handle any type of exception (i.e. catch Exception) and print out a user-friendly error message to the console within catch. k. Test your exception handling by entering some faulty input when the program runs, such as a non- numeric value in the age portion. You do not need to include the test results in your submission, but you should run a test to ensure that the exception handling is working properly. ple Input: ase enter name, age,city: John, 25, Boston ple Output: Sample Input: Please enter name, age,city: John, 25, Boston Sample Output: Name: John (length: 4) Age: 25 Age in 10 years: 35 City: Boston (length: 6) Sample Exception-Handling Output: Sorry, but an error has occurred. Please check your input and try again
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
