15-121 Homework 3: Grade Book - Due 10/2 at midnight
Download and unzip hw3-code.zip, which contains the
versions of the Person.java and the GradeBook.java files. The
Person class is unchanged from HW2, but will require major changes.
The GradeBook class is new for this assignment and replaces the array
used in HW2's address book with an ArrayList of Person. There is
also a new data file, 121grades.txt to be used with this assignment. Of
course, the grades are made up (don't take anything personally), but you can
change your own grades as you see fit! You will also have to create a new
class completely from scratch, called Grade.java.
Note: You will be graded in part on your coding style. Your code
should be easy to read, well organized, and concise. You should avoid
Background: A Grade Book
The purpose of this homework is to give you more programming practice
utilizing a major data structure in Java, the ArrayList. You will
also obtain practice writing and testing a class from scratch! In this
homework, you will implement a simple gradebook for a course. The grade book
will consist, basically, of an ArrayList of Persons. Each
student will be an instance of the Person class, but you will have to
augment the Person class with a private instance variable that can
hold an ArrayList of Grades. There are other, better ways
to accomplish this, but it will work for this assignment, whose focus is on
ArrayLists and their operations. You will also need to write
the Grade class.
The Data File format
The data file for this assignment consists of a student's first name, last
name, andrew id, followed by a number of "grade pairs". Each "grade pair"
consists of the name of the grade (homework, quiz, etc.) followed by the
actual grade for that assignment. To keep things simple, assume you have only
4 categories of grades: homeworks (HWn), quizzes (Qn), midterm
(MT) and Final (F). See 121grades.txt for an example.
The Grade Class
The Grade class will represent a single grade. A grade has three
components, a name (stored as a String, e.g., HW1), a weight (stored
as a double), and the actual grade (stored as an int). You
will need to write a constructor for this class as well as a few methods (most
likely, you will need a method to get an actual grade, get a category and/or
its weight, and change an actual grade). As dictated by the course policy,
homewoks have weight 0.07, quizzes have weight 0.015, the midterm weight is
0.14, and the final weight is 0.25. You may assume these weights are
The GradeBook Class
You will need to write the following methods in the GradeBook
This constructor needs to
be modified to work with the new file format. In particular, you will need to
decide how to incorporate the reading of the grades. You will want to use the
number of the grade pairs in a loop, but will have to decide how to get the
grades into the ArrayList of Grades in the Person
class. I would suggest building a Person with the names and id and
then create a method called addGrade to add each grade to
a Person object. YMMV.
Needs to be modified to correctly return a properly formatted (spaced) String
that represents the contents (used cells) of the grade book.
void removePerson(String id)
Removes the entry for the person with andrew ID, id, from the grade
book, using the appropriate ArrayList method.
void printIndividualGrades(String id)
Prints all the grades, nicely formatted, that are associated with the student
with andrew id id. Prints nothing if no entries match the specified
void printRunningGrade(String id)
Searches for the student with the specified andrew id and prints the current
letter grade for that student, if found. If there is no such student, prints
an appropriate error message. The current letter grade for a student can be
determined by multiplying the actual grade times the weight for each
assignment, summing all of these multiplications, and then dividing by the
sum of all the weights. Then apply the standard 90 and above is A, 80 to 89
is B, etc.
void changeGrade(String id, String assignment, int newgrade)
If a person with andrew ID, id, exists, changes the grade associated
with assignment to newgrade. Should print an appropriate error
message if either the id or assignment cannot be found.
Prompts the user for a new assignment to add to all the students, then loops
through all the students, asking the user for a grade for the new assignment.
Updates each Person object by adding the new assignment name and
grade to the ArrayList of Grades for that person.
void updateDatabase(String filename)
Creates a file with name provided by filename and writes the contents
(used cells) of the grade book to this file.
Some of the methods you will write in the GradeBook class will
require that you change/add methods in the Person class. Others may
require a different getter or setter.
Of course, you will also need to test your methods by calling them from main.
Submitting Your Work
When you have completed this assignment and tested your code thoroughly,
create a .zip file with your work (including the Grade.java,
Person.java and GradeBook.java). Name the zip file
"your-last-name".zip and email it to
Make sure to keep a copy of your work just in case something goes wrong!