CS 132: Intro to Computer Science II

Spring 1999

Assignment 6

Sorting an Array of Objects

Due Monday, March 8

For this assignment you will write classes to grade a multiple-choice exam for up to 20 students. For each student the program will read in an identification number and that student's answers on a multiple-choice test. The exam is "graded" by comparing a students' answers to the answer key. The percent right is computed and stored along with the student id number. After all exams have been graded, the program produces the results in two ways:

Below is a sample run. Your program should produce similar, but not necessarily identical, output:

whoville% java Grade
.
.
.
For each student, please enter an id number and the student's answers to the 10 questions.
When all students have been processed, enter -1 to quit.

Student id:  1234
Answer #1: 1
Answer #2: 0
Answer #3: 1
Answer #4: 1
Answer #5: 0
Answer #6: 1
Answer #7: 1
Answer #8  1
Answer #9: 0
Answer #10: 1
Student # 1234 scored 70%.

Next student id (or -1 to quit): 7843
Answer #1: 0
Answer #2: 0
Answer #3: 1
Answer #4: 1
Answer #5: 0
Answer #6: 1
Answer #7: 1
Answer #8  0
Answer #9: 0
Answer #10: 1
Student # 7843 scored 50%.

Next student id (or -1 to quit): 4516
Answer #1: 0
Answer #2: 0
Answer #3: 0
Answer #4: 0
Answer #5: 0
Answer #6: 0
Answer #7: 0
Answer #8  0
Answer #9: 0
Answer #10: 0
Student # 4516 scored 0%.

Next student id (or -1 to quit): 7825
Answer #1: 1
Answer #2: 1
Answer #3: 1
Answer #4: 1
Answer #5: 1
Answer #6: 1
Answer #7: 1
Answer #8  1
Answer #9: 1
Answer #10: 1
Student # 7825 scored 100%.

Next student id (or -1 to quit): -1

The results sorted by score are:

ID         Score
4516       0
7843       50
1234       70
7825       100


The results sorted by id are:

ID          Score
1234        70
4516        0
7825        100
7843        50

 
   


Copy the code for class Student which defines a Student object with two fields: id number and test score from~wenk/cs132/lab6. It also contains the methods for accessing and changing these values.

You are asked to write a class GradeExam which creates an array of Student objects and implements methods to:

You will also need to write class Grade which creates an object of type GradeExam and calls its methods to process the students' exams. It should call at least one static method.

Submission

Turn in hardcopies of GradeExam.java and Grade.java as well as a script of you running the program.