COP 2210 sections 5, 6 & 7

Assignment 4: classroll

Due Date: April17, at the beginning of the class. Late assignments will not be accepted.

Write a program tohelp maintain a class roll. Your program must contain three classes: Student, Exams, and ClassRoll.

This assignment must be completed in groups of two students. You can’t work with the same person you worked with for assignment 1 or 2. Teams of more or less than 2 students are not accepted. Turn in a printout of your program and sample input/output. Your printout must have the names of both members of your teams.

Class Exams: Students take three exams maintained by the class:

Private Instance

Variables:

/

int score1

/

Score of the first exam

int score2

/

Score of the second exam

int score3

/

Score of the third exam

Constructor

/

No parameters

/

Initializes all exam scores to zero

Public Methods:

/

voidsetScore1(intsc)void setScore2(intsc)void setScore3(intsc)

intgetScore1()

int getScore2()

intgetScore3()

/

Setters and getters for each of the scores

String toString()

/

Returns a string containing the scores in each of the three exams.The information must be formatted properly.

Class Students:The class Student maintains student information:

Private Instance

Variables:

/ String fName /

The first name of the student

String lName /

The last name of the student

Exams scores /

Scores for three exams

Constructor

/

Students(String fn, String ln)

/

Initializes fName and lName to fn and ln, respectively. Initializes scores to 0.

Public Methods:

/

void setScore1(intsc)

voidsetScore2(intsc)

void setScore3(intsc)

/

Setters for each of the scores

String toString()

/

Returns a string containing student’s first name, last name and scores in each of the three exams. The information must be spaced properly.

doublegetAverage()

/

Returns the student’s average in three exams

intcompareTo(Student s)

/

Returns:

-1, if the student’s name appears before
s’s name in alphabetical order
1, if the student’s name appears after
s’s name in alphabetical order
0, if the student’s name equals s’s name
Student name is fName + “,” + lName

Class ClassRoll:This class maintains student information (arbitrary number of students) for one course:

Private Static Variables

/ ArrayList of students /

Students in the class

String title /

The course title

String filename /

The name of the input/output file

Constructor

/

ClassRoll(String f)

/

Read the class roll data from the input file f, creates Student objects for each of the students and adds them to the Array of students.

The input file contains the course title on the first line. The data for each student appears on a separate line consisting of first name, last name, score1, score 2, and score3 separated by at least one space.

Public Methods:

/

voidremove()

/

Prompts the user for the first name and last name of a student and removes the student from the list of students. In case the student is not found in the list of students, an appropriate message is displayed.

void display()

/

Displays the class roll: the course title on the first line and each student record (first name, last name, score1, score 2, score3 and average) on a separate line. The class average must also be displayed. The class roll must be properly formatted.

void add()

/ Prompts the user for the first name, last name and three scores of a student, creates a student object with the input data and adds the student to the end of the list of students. In case the student is already in the list of students, an appropriate message is displayed.

void changeScore1()

/ Prompts the user for user for the first name, last name and score 1 of a student and change the first score of the student. In case the student is not found in the list of students, an appropriate message is displayed.

void changeScore2()

/ Prompts the user for user for the first name, last name and score 2 of a student and change the first score of the student. In case the student is not found in the list of students, an appropriate message is displayed.

void changeScore3()

/ Prompts the user for user for the first name, last name and score 3 of a student and change the first score of the student. In case the student is not found in the list of students, an appropriate message is displayed.

void find()

/

Prompts the user for the first name and last name of a student and displays the student’s three scores and average

voidsortAverage()

/

Sorts the class roll in descending order of student averages and displays the sorted list.

void sortNames()

/

Sorts the class roll in ascending order of student names and displays the sorted list.

void save()

/

The list of students is saved back to the datafile (fileName)

Class Assignment4:

Public static Methods:

/

voidmain(String[] args)

/

Prompts the user for the name of the input file and creates a ClassRoll object. It then repeatedly displays the list of available commands (invokes method prompt()) and based on the user input invokes an appropriate method from the ClassRoll object. The user can only enterthe commands described in the method prompt below. If an incorrect command is entered, the user must be given an appropriate message

The method displays a goodbye message and terminates when the command q (or quit) is entered. The commands can be entered in any combination of lower and upper case letters

voidprompt()

/

Displays the list of available commands as follows:

a or add to add a student in the class roll
sa or average to sort the students based on their average
sn or names to sort the students based on their last names
r or remove to remove a student from the class roll
s or save to save the list of students back to the input datafile
c1 or change1 to change score 1 of a student
c2 or change2 to change score 2 of a student
c3 or change3 to change score 3 of a student
f or find to find a student in the class roll
d or display to display the class roll
q or quit to exit the program

Sample input/output:

Assuming that the file data.txt contains:

COP2210

John Doe 50 60 70

Marco Boyle 50 60 73

Eric Munzon 45 100 90

Marry Able 95 100 100

Jack Smith 100 100 100

Elizabeth Gomez 100 100 100

The following is a sample input output:

run:

What is the name of input file: data.txt

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: d

COP2210

John Doe 50 60 70 60.00

Marco Boyle 50 60 73 61.00

Eric Munzon 45 100 90 78.33

Marry Able 95 100 100 98.33

Jack Smith 100 100 100 100.00

Elizabeth Gomez 100 100 100 100.00

The class average is: 82.94

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: a

Enter the student's first name

Mike

Enter the student's last name

Able

Enter Student's first score

90

Enter Student's second score

91

Enter Student's third score

92

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: d

COP2210

John Doe 50 60 70 60.00

Marco Boyle 50 60 73 61.00

Eric Munzon 45 100 90 78.33

Marry Able 95 100 100 98.33

Jack Smith 100 100 100 100.00

Elizabeth Gomez 100 100 100 100.00

Mike Able 90 91 92 91.00

The class average is: 84.10

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: f

Enter the student's first name

Marco

Enter the student's last name

Boyle

Marco Boyle 50 60 73 61.00

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: c1

Enter the student's first name

Marco

Enter the student's last name

Boyle

Enter Student's first score

70

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: d

COP2210

John Doe 50 60 70 60.00

Marco Boyle 70 60 73 67.67

Eric Munzon 45 100 90 78.33

Marry Able 95 100 100 98.33

Jack Smith 100 100 100 100.00

Elizabeth Gomez 100 100 100 100.00

Mike Able 90 91 92 91.00

The class average is: 85.05

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: c2

Enter the student's first name

Marco

Enter the student's last name

Boyle

Enter Student's second score

80

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: c3

Enter the student's first name

Marco

Enter the student's last name

Boyle

Enter Student's third score

80

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: d

COP2210

John Doe 50 60 70 60.00

Marco Boyle 70 80 80 76.67

Eric Munzon 45 100 90 78.33

Marry Able 95 100 100 98.33

Jack Smith 100 100 100 100.00

Elizabeth Gomez 100 100 100 100.00

Mike Able 90 91 92 91.00

The class average is: 86.33

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: c3

Enter the student's first name

John

Enter the student's last name

Jones

Student not found

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: sa

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: d

COP2210

Jack Smith 100 100 100 100.00

Elizabeth Gomez 100 100 100 100.00

Marry Able 95 100 100 98.33

Mike Able 90 91 92 91.00

Eric Munzon 45 100 90 78.33

Marco Boyle 70 80 80 76.67

John Doe 50 60 70 60.00

The class average is: 86.33

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: sn

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: d

COP2210

Marry Able 95 100 100 98.33

Mike Able 90 91 92 91.00

Marco Boyle 70 80 80 76.67

John Doe 50 60 70 60.00

Elizabeth Gomez 100 100 100 100.00

Eric Munzon 45 100 90 78.33

Jack Smith 100 100 100 100.00

The class average is: 86.33

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: r

Enter the student's first name

Marco

Enter the student's last name

Boyle

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: d

COP2210

Marry Able 95 100 100 98.33

Mike Able 90 91 92 91.00

John Doe 50 60 70 60.00

Elizabeth Gomez 100 100 100 100.00

Eric Munzon 45 100 90 78.33

Jack Smith 100 100 100 100.00

The class average is: 87.94

Enter one of the following commands

a or add to add a student in the class roll

sa or average to sort the students based on their average

sn or names to sort the students based on their last names

r or remove to remove a student from the class roll

s or save to save the list of students back to the datafile

c1 or change1 to change score 1 of a student

c2 or change2 to change score 2 of a student

c3 or change3 to change score 3 of a student

f or find to find a student in the class roll

d or display to display the class roll

q or quit to exit the program

Enter the next command: r

Enter the student's first name

Marco

Enter the student's last name