## CSci 1211 Problem set 7. Due Friday, March 19th at 5pm

### Problem 1 (40 points)

Write a class `StudentGrades` which stores information about a student's grades in a class. Specifically, an object stores:
• The student's name
• Grades for 5 problem sets, each grade is an integer between 0 and 10)
• Grades for the midterm and the final exams each grade is an integer between 0 and 100.
The class must provide the following methods:
• A constructor that takes a student's name as a parameter.
• `toString` prints the state of the object in the following format:
```Ann Smith       PS: 5 7 9 10 5          Midterm: 73     Final: 67
```

Use '\t' for tab to format the output.
• `setMidterm` and `setFinal` for setting the grades for the midterm and the final. If the value of the parameter is not within the range 0 to 100, an error message is displayed and the value is not set.
• `setProbSetGrade` which sets the grade for a specific problem set (i.e. it takes two parameters: the number of the problem set and the grade). As the in previous two methods, an error message is displayed for an illegal value and no value is set. Note that the problem set number could be illegal as well.
• `getName, getMidterm, getFinal`, and `getProbSetGrade` to get the values of the name, the midterm grade, the final grade, and the grade for a particular problem set.
• `getProbSetAverage` returns the average of the problem sets (what type does it return?)
• `getTotal` returns the total numerical score. The midterm is 20% of the grade, the problem sets and the final are 40% each.
• `getLetter` returns the student's letter grade for the class as a character according to the following table:
90-100 A
80-90 B
70-80 C
60-70 D
< 60 F
• `passed` returns true if the student passed the course, false if he/she failed.
Important: don't try to write all the methods at once, add them as you need them in the test class (see below).

Write the test class `StudentGradesTest`. Here is what you need to do:

• Create an array of 5 objects of class StudentGrades, create 5 objects of the class, initialize the names. You need to write the StudentGrades constructor for this.
• Randomly generate and set grades for the problem sets, the midterm, and the final for each student (you will need all of your 'set' methods for this). The grades for the problem sets should be between 5 and 10, the grades for the exams between 50 and 100. Think carefully of the parameters for the random number generator (it's a bit tricky!). Run your program several times to make sure that you get all possible scores for the problem sets
Test the results by printing out the objects (you need the toString method for that).
• Additionally test the set methods for illegal values to make sure that they display the error message and don't change the value.
• Write the getProbSetGrade method. Find the average on the 3rd problem set (what would be the parameter of the method?)
Test this method for an illegal problem set number.
• Write the method getProbSetAverage. Find the student with the highest problem set average and print out his/her name and the average.
• Write the methods getMidterm and getFinal. Print out the names of students who got a perfect score on a midterm or on a final, print out the number of such students. A student who got a perefect score on both exams will be counted once.
• Write the methods getTotal and getLetter. For each student print out the name, the total score, and the letter grade.
• Write the method `passed`. Print out the names of students who failed the course. If there are no such students, print out "Everyone passed".
A sample program output is like this:
``````
Ann Smith       PS: 8 9 7 5 9           Midterm: 88     Final: 52
Brian Peterson  PS: 6 7 9 8 5           Midterm: 74     Final: 90
Carol Matthews  PS: 6 6 8 7 7           Midterm: 86     Final: 58
Darrel Green    PS: 5 10 6 8 5          Midterm: 69     Final: 55
Ellen Lee       PS: 5 9 6 5 9           Midterm: 56     Final: 71
Invalid problem set number 5
The average on the 3rd problem set is 7.2
Invalid problem set number 6
The grade of Ann Smith on problem set 6 is -1
Ann Smith has the highest problem set average 7.6
0 students have a perfect exam score
Ann Smith       68.8    D
Brian Peterson  78.8    C
Carol Matthews  67.6    D
Darrel Green    63.0    D
Ellen Lee       66.8    D
Everyone passed
``````
Don't worry about minor problems with formatting. It's OK if your output looks like this:
``````
Ann Smith       72.8    C
Brian Peterson  87.8    B
Carol Matthews  66.80000000000001       D
Darrel Green    75.2    C
Ellen Lee       64.0    D
``````

This assignment is quite involved. Make sure to start early. If you have questions, please ask! The best way to do it is to e-mail the class list. You are also encouraged to answer each other's questions. However, please do not send your code to the class list.

Happy programming!

This page is a part of the course CSci 1211 at UMM.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.