$30
CS520 Module 5 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 HW5_lastName and complete the
following requirements.
Create a package named cs520.hw5. 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. This is a modification of HW3 using arraylist.
a.The instance (or member) private variables – name (String), homeworks
(an integer ArrayList).
b.A single constructor with name as its argument. Also, initialize the
homeworks arraylist.
c. The public get and set methods for the name instance variable.
d.A void addHomeworkGrade method which takes one argument – the
new homework grade.
e.A public computeAverage method which takes no arguments and
returns a double showing the average homework grade for this
student.
f. Override the toString method to return the string representation of this
object in the format “The <studentName>’s average grade is <the
computed average>”.
2. Create a Test class to test the following functionality in its main method.
a. Declare and initialize an empty Queue of Student objects named
studentQueue.
b. Declare and initialize an empty HashMap named studentMap.
The keys will be the names of the students and the entries in the
map will be the corresponding student objects.
c.Use the BufferedReader class to read the data.txt file. The contents
of the file are shown below. Create the data.txt file in
HW5_lastName.
d. 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. In this loop,
1. Invoke the processInputData method for each line read. This
method returns the corresponding Student object.
2. Add this Student object to the studentQueue.
3. Insert this Student object into the studentMap using the
student’s name as the key.
e. After the loop is processed, do the following.
1. Iterate over the studentQueue and display each element to
the console.
2. Access the keys of the studentMap and assign them to an
appropriate variable. Create an iterator over the keys. Iterate
over each key in this set and display the associated object in
the map to the console.
Write a private method processInputData with return type Student
which processes its string input argument and returns the
corresponding Student object as follows.
1. Tokenize the string argument using the StringTokenizer class
using the comma as the delimiter, or using the String split
method.
2. Extract the name token. Create a Student object and assign
to the local variable currentStudent.
3. Using a while loop, read the next homework grade token.
Use the addHomeworkGrade method on the student
object to add the homework grade for this homework.
4. Display the string representation of the currentStudent
object to the console.
5. The method should return the currentStudent object.
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:
Submission:
Create an archive of your Eclipse project using the following steps. Select the
HW5_lastName project in the Eclipse IDE’s Package Explorer or the Navigator
window.
Click File->Export. Select the General->Archive File option. Click Next.
Specify the “To archive file:” entry as say, C:\Temp\HW5_lastName.zip.
The zip file will be created and stored in the C:\Temp folder.
Submit this zip file as an attachment in the Assignment Section.