CS520 Week 3 Assignment

General Rules for Homework Assignments • You are strongly encouraged to add comments throughout the program. Doing
so will help your facilitator to understand your programming logic and grade
you more accurately. • You must work on your assignments individually. You are not allowed to copy
the answers from the others. However, you are encouraged to discuss the
approaches to the homework assignments with your section mates and the
facilitator in your section via the discussion board. • Each assignment has a strict deadline. However, you are still allowed to submit
your assignment within 2 days after the deadline with a penalty. 15% of the
credit will be deducted unless you made previous arrangements with your
facilitator and professor. Assignments submitted 2 days after the deadline will
not be graded. • When the term lastName is referenced in an assignment, please replace it with
your last name.
You are strongly encouraged to add comments into your program!
Create a new Java Project in Eclipse named HW3_lastName and complete the
following two parts.

Part 1 (40 Points) – Strings 
Create a package named cs520.hw3.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 course id, course
name, and tuition in the format
CourseId,CourseName,Tuition 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 course id part of the input
using the substring method. e. Display the position of the first comma, the course id, and the
length of the course id to the console. f. Find the index of the second comma in the input using the indexOf
method. Using this value, extract the course name part of the input
using the substring method. g. Display the position of the second comma, the course name, and
the length of the course name to the console. h. Extract the tuition using the substring method. Convert the value to
an integer. Display to the console the tuition and the tuition at 25%
discount (as integers). i. Now, 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 user.
Also, test the following inputs where exceptions will occur and your program
handles them gracefully -- when Cancel is clicked, when only the course id
is entered, when only the course id and the course name are entered, and
when all the three values are specified but the tuition is not an integer


Part 2 (60 Points) – StringTokenizer and File Input 
Create a package named cs520.hw3.part2. Using this package, create the following
classes. 1.Create a class named Student as follows. The class keeps track of the
student’s homework grades. a.The instance (or member) private variables – name (String),
homework1, homework2, homework3, homework4, homework5 and
homework6 (all of type integer). b.A single constructor with name as its argument. c. The public set methods for the six homework instance variables. The
get methods are optional. d.A public computeAverage method that takes no arguments and returns
a double showing the average homework grade for this student. e.Override the toString method to return the string representation of this
object in the format “The ’s average grade is ”.
 2. 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
HW3_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. 1. Tokenize the string argument using the StringTokenizer class
using the comma as the delimiter. 2. Extract the name token. Create a Student object and assign
to the variable currentStudent. 3. Read each homework grade token one token at a time. Use
the corresponding set method on the student object to set
the instance value. 4. Display the string representation of the currentStudent object
to the console.
Sample Input data.txt file:
Alice,44,79,85,72,77,57
Bob,79,94,70,71,71,51
Charlie,95,99,41,55,65,50
Dave,87,89,88,55,74,63
Ed,82,51,44,67,73,49  Sample Output: 
attached  is the solution
Powered by