Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Programming Question: Create a package named cs520.hw3.part1. Using this package, create the class StringTest and implement the specified functionality in its main method. 1.

JAVA Programming Question:

Create a package named cs520.hw3.part1. Using this package, create the class StringTest and implement the specified functionality in its main method.

1. Ask the user, through a single input dialog, for the name, age, and their city in the format Name,Age,City. Be sure to trim the users input, in case spaces were entered at the beginning or at the end.

2. Display the trimmed data to the console. Do the following operations using this trimmed string: Find the index of the first comma in the input using the indexOf method. Then, using this value, extract name part of the input using the substring method. Display the position of the first comma, the name, and the length of the name to the console.

3. Find the index of the second comma in the input using the indexOf method. Using this value, extract the age part of the input using the substring method. Display the position of the second comma, and the age to the console. Convert the value to an integer. Display to the console their age in 10 years.

4. Extract the city using the substring method. Display to the console the city and the length of the city to the console. Be sure to examine the code for all possible exceptions that could occur. Handle all the different exceptions explicitly and print out the appropriate exception message to the console.

image text in transcribed

SAMPLE OUTPUT:

image text in transcribed

Sample Input: Input Enter data using the format Name,Age,City John Doe,25,Bostorn Cancel OK

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

KEY QUESTION Refer to columns 1 and 6 in the table for question

Answered: 1 week ago