|Get Selected Weeks Solution with ONLY||NOT||Add Selected Tutorials To Cart|
Part 1 (40 Points) – Strings
Create a package named cs520.hw4.part1. Using this package, create the class StringTest and implement the specified functionality in its main method.
a. Ask the user, through a single input dialog, for the user’s first name, last name, and age in the format
b. Trim the user’s input, in case spaces were entered at the beginning or at the end.
c. Display the trimmed data to the console. Do the following operations using this trimmed string.
d. Find the index of the first comma in the input using the indexOf method. Using this value, extract the first name part of the input using the substring method.
e. Display the position of the first comma, the first name, and the length of the first name to the console.
f. Find the index of the second comma in the input using the indexOf method. Using this value, extract the last name part of the input using the substring method.
g. Display the position of the second comma, the last name, and the length of the last name to the console.
h. Extract the age using the substring method. Convert the value to an integer. Display the age in 10 years from now.
Now, examine the code for all possible exceptions that could occur. Using a single try-catch construct, handle all the different exceptions explicitly and print out the exception message.
Also, test the following inputs where exceptions will occur and your program handles them gracefully -- when Cancel is clicked, when only the first name is entered, when only the first name and the last name are entered, and when all the three values are specified but the age is not an integer
Part 2 (60 Points) – StringTokenizer and File Input
Create a package named cs520.hw4.part2. Using this package, create the following classes.
Create a class named Student as follows. The class keeps track of the student’s homework grades.
The instance (or member) private variables – name (String), homework1, homework2, homework3, homework4, homework5 and homework6 (all of type integer).
A single constructor with name as its argument.
The public set methods for the six homework instance variables. The get methods are optional.
A public computeAverage method which takes no arguments and returns a double showing the average homework grade for this student.
Override the toString method to return the string representation of this object in the format “The <studentName>’s average grade is <the computed average>”.
Create a Test class to test the following functionality in its main method.
a.Use the BufferedReader class to read the data.txt file. The contents of the file are shown below. Create the data.txt file in HW4_lastName.
b.Read the contents of the text file one line at a time using a loop. The program should work for any number of input lines. Invoke the processInputData method for each line read.
c. Write a private method processInputData which processes its string input argument as follows.
Tokenize the string argument using the StringTokenizer class using the comma as the delimiter.
Extract the name token. Create a Student object and assign to the variable currentStudent.
Read each homework grade token one token at a time. Use the corresponding set method on the student object to set the instance value.
Display the string representation of the currentStudent object to the console.
Sample Input data.txt file:
My tutorial contains Java Programs - Eclipse Project and Document.
If you have more questions, please contact me via email firstname.lastname@example.org
I will help you any time
Thank you !