Transcribed TextTranscribed Text

Part 1 Strings Exceptions Create package narned cs520 hw3.part1 Using this package, create the class String Test and implement the specified functionality in its main method a Ask the user, through single input dialog for the name, age, andtheir city format Name Age,City b. Trim user's input incase spaces were entered at the beginning orat c. Display the trimmed data the console. Do the followingoperations the end using trimmed string. d. Find index the first comma in the input using the inder Using this value, extract name part the input using the substring method e Display the position the first comma, the name, and the length of the name the console f. Find the second comma nthe input using the indexOf method. Using this value, extract the age part the input usingthe substring method. g Display the position the second comma and the age theconsole Convert the valuete integer Display econsole their age in 10 h. Extrac the city using the substring method Display tothe console the city length console i. Now. examine code all possible exceptions that could occur. Handle ceptions explicitly and print out theappropriate exception console. Sample Input: . Input Enter using the format John Cancel Sample Output: John Doe, 25. Boston First Comma Position:8, Name:John Doe, Length:8 Second Comma Position:11, Age:25 Your will be 35 in 10 years from now! City:Boston, Length:6 Also, test the following inputs where exceptions will occur and your program handles them gracefully when Cancel clicked when only the name is entered when only the name and the age are entered and when lithe three values are specified but the age not an integer Part 2 File Input Create package narned cs520.hw3.part2 Using this package, create the following dasses 1. Create dass named Senator as a The name, party, state(String). b.Asingle constructor with narne asits argument. c.The public getand set methods forthe instance variables. d. Override toString string representation of this () from has been the senator for years- 2. Create following functionality its main method a.Use the BufferedReader class read date.tx file The shown below. Create the data.bxt file in HW3_ lastName folder b.Read the contents text file one line at a time usino aloop The program should work for number input lines Invoke the Date each line read c. Write aprivate processinputData which processes its string input argument follows. argu ment using the StringTokenizer class using the comme the delimiter. 2. Extract token Create Senator object dassign 3. Read fthe tokens one token time. Use the currentSenatorobjectto set the lithe nota i.e. throws an set the value as -99in the exception Display of the currentSenatoro tothe console Sample Input data.bxt file Al Franken, Amy Klobuchar Democrat Minnesota Angus King, Independent Maine Ben Cardin, 10, ,Democrat,Maryland Ben Sasse, Republ ican, Nebras ska Bernie Sanders 10, Independent Vermont Sample Output Al Fronken (Democrat) from Minnesoto has been the senator for years Amy Klobuchor (Democrat) from Minnesota has been the senator for years Angus Kina from the senator for from has beer senator Ben Sesse (Republican) tom Nebrosko has beer the senator tos vears Bernie Sanders (Independent) from hes been the senator for

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package cs520.hw3.part1;
// Import libraries
import javax.swing.JOptionPane;

// Beginning of StringTest Class
public class StringTest
// Beginning of Main Method
public static void main(String[] args)
// Declare and Set Variables
String commaSeperator=",";
String personName="";
String cityName="";
String aMsg="";
int personAge=0;
int firCommaP=0;
int secCommaP=0;
// Try block for the JOption Pane Entry
// Declaring and setting input line with prompt dialog
String inpLine = JOptionPane.showInputDialog(null, "Enter data using the format Name,Age,City: ", "Input", 1);
// Checks input value if null
// Message box with selecting cancel button is clicked
JOptionPane.showMessageDialog(null, "You selected the cancel button.", "Message", 1);
// Declare array split line with comma separator
String[] splitVal = inpLine.split(commaSeperator);
// Checks to see if the trimmed input line is null or length is 0
if((inpLine.trim().equals("")) || (splitVal.length==0))
// Message Box to re-enter the values according to given format
JOptionPane.showMessageDialog(null, "Please enter data in the following format Name,Age,City.", "Message", 1);
// Checks if the split value length is 0
// Message alert to inform the user to enter the name, age and city
aMsg=aMsg+"Please enter the Name, Age and City.\n";
// Checks if the split value length is 1
else if(splitVal.length==1)...

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats