java program to manage the grades of one college course
COP2800 - Java Programming Course Project
Fall 2014 Page 1 of 8 Juan López
INSTRUCTIONS: In this project, you will create a java program to manage the grades of one college course. The user interface for the program will be text-menu driven. Figure 1 depicts what the menu should look like upon launching the program. ================================================ 1 - Add student to course 2 - Add exam grade for student 3 - Remove a student from course 4 - Show grades for 1 student 5 - Show grades for all students in the course 6 - Save course to file 7 - Load course from file 8 - Quit program ================================================ Enter selection between 1 and 8: Figure 1 - Menu for course program 1 - Read all instructions CAREFULLY! The User interface is described in Section 1 of this document. The Java Classes you must implement are described in Section 2 of this document. 2 - All programming must follow the guidelines in Appendix I of the text book (page A-79). 3 - The Project must be submitted as a zipped Java Application as implemented on NetBeans. 4 - The Project must be uploaded by Dec 1, 11:59 PM (Monday). 5 - Extra credit opportunities are listed in the last page. They are optional.
COP2800 - Java Programming Course Project
Fall 2014 Page 2 of 8 Juan López
SECTION 1: USER INTERFACE The program will behave in the following manner: A - Menu: Menu item selection must be validated.
Upon program launching, the Menu will be drawn on the screen (see Figure 1). If a user enters an invalid menu number, the program must advise the user to enter a valid selection, and try again.
B - Menu Selections: Selection 1 - Add Student to a course
When user selects item 1, the program asks the user for the Student's last name, first name, student id, and her year in college. If the Student ID provided is not in the course, the program then adds the student to the course, and prints out the student’s record confirming the addition:
Student added successfully: Student ID: 1234 Student Name: Smith, Joan Year in School: 4 Grades: <none>
The program will validate that a student with that ID is not already in the course:
================================================ 1 - Add student to course 2 - Add exam grade for student 3 - Remove a student from course 4 - Show grades for 1 student 5 - Show grades for all students in the course 6 - Save course to file 7 - Load course from file 8 - Quit program ================================================ Enter selection between 1 and 8: 1 Enter student ID: 1234 ERROR: Student ID already exists.
(hint: a new Student object should be created, then added to the Course object's ArrayList of Students).
COP2800 - Java Programming Course Project
Fall 2014 Page 3 of 8 Juan López
Select 2 - Add an exam grade for a student When user selects item 2, the program prompts the user for the student’s id.
If there is no student with the ID entered, the program will let the user know, and then re- output the main menu.
If a student is found, the program will ask the user for the grade. Grades will be between 0 and 100. The system will not hold more than 5 grades per student.
After adding the grade, the program will print out the student’s record, confirming the addition of the new grade:
Student grade added successfully: Student ID: 1234 Student Name: Smith, Joan Year in School: 4 Grades: 82 Average: 82.0
Select 3 - Remove a student from the course
When user selects item 3, the program prompts the user for the student's id. If there is no student with the ID entered, the program will let the user know, and then re- output the main menu. If there is a student with that id, the program prints the student info then asks user to confirm he wants to delete the student from the course.
Student ID: 1234 Student Name: Smith, Joan Year in School: 4 Grades: 82 Average: 82.0 Are you sure you want to delete? (Y/N):
If the user responds with a "Y", the program then deletes the student from the course and outputs the confirmation.
Student 1234 deleted. (hint: the program first finds the Student that needs to be deleted from the Course object's Student ArrayList. Upon the user confirming, the program deletes that Student object from the Course object's ArrayList of Students)
COP2800 - Java Programming Course Project
Fall 2014 Page 4 of 8 Juan López
Select 4 - Show grades for 1 student in the course
When user selects item 4, the program prompts the user for the student's id. The program then prints out the student's grade in the following format:
Student record: Student ID: 1234 Student Name: Smith, Joan Year in School: 4 Grades: 82, 94, 89 Average: 89.0
Select 5 - Show grades for all the students in the course When the user selects item 5, the program will print a list of all the students and their grades in the following format:
Course roster: ID Name Year Grades Average --------------------------------------------------------------------------------- 1234 Lopez, Juan 3 2, 86, 98 62.00 1235 Alvarez, Jeanie 5 95 95.00 1237 Washington, Jerome 3 <no grades> 0.00 1240 Pierre, Monique 3 <no grades> 0.00
Select 6 - Save course to file When the user selects item 6, the program will prompt the user for the file name. The program then saves the file in the format depicted on Figure 2. If the file cannot be created, the program will return an error message to the user, then take the user back to the main menu
Figure 2 - Course file format - use the pipe (“|”) as the delimiter
1234|Lopez|Juan|3|3|2|86|98|-1|-1
1235|Alvarez|Jeanie|5|1|95|-1|-1|-1|-1
1237|Washington|Jerome|3|0|-1|-1|-1|-1|-1
Student ID
Last Name
First Name
Year in School
Number of Grades
Grades (up to 5, -1 means no grade exists)
COP2800 - Java Programming Course Project
Fall 2014 Page 5 of 8 Juan López
Select 7 - Load course from file When the user selects item 7, the program will prompt the user for the name of the file to be loaded. The file to be loaded will be of the same format depicted in Figure 2. If the file could not be loaded, the program will return an error message to the user, then outputs the main menu. Select 8 - Quit Program When the user selects item 8, the program prints the word "Goodbye!", then exits.
Goodbye!
COP2800 - Java Programming Course Project
Fall 2014 Page 6 of 8 Juan López
SECTION 2: JAVA CLASSES Your java program must implement at least 3 classes as described below. 1 - CourseUI class The CourseUI class has the user interface to the program. It should present all output to user and receive all input from the user. This class should have one This class needs only one method - the main method. Your solution should have much more than one method, to make the code readable. 2 - Student class The Student class has all information about 1 student: last name (a string) first name (a string) year in school (an integer from 1 - 5) student id (an integer between 1 and 99999) an Array of exam scores. each exam score is an integer from 0 - 100. a student will have no more than 5 exam grades The Student class should have at least the following public methods: Constructors: Student(int inId, String inLastName, String inFirstName, int inYearInSchool) Student(String inRecordStringFromFile) Accessors: String getStudentName() String getId() String getYearInSchool() String getGrades() double getAverageGrade() String getStudentFileString() Mutators: void setLastName(String inLastName) void setFirstName(String inFirstName) void setId(int inId) void setYearsInSchool(int inYears) void addExamScore(int inScore)
void removeExamScore(int scoreNbr)
for extra credit
COP2800 - Java Programming Course Project
Fall 2014 Page 7 of 8 Juan López
SECTION 2: JAVA CLASSES (continued) 3 - Course class The Course class has the information about the course: an ArrayList of Student objects
name of the file (a string) flag to know whether file has changed (a boolean)
The Course class should have at least the following public methods: void addStudent(in inId, String inLastName, String inFirstName, int yearInSchool) void removeStudent(int inStudentID)
void addScoreToStudent(int inStudentID, int inScore) void removeScoreFromStudent(int inStudentID, int inScore) Student getStudent(int inStudentId)
String getStudentGrades(int inStudentId) String getAllStudentGrades() void saveCourseToFile(PrintWriter inOutput) void loadCourseFromFile(Scanner inFileName)
for extra credit
for extra credit for extra credit
COP2800 - Java Programming Course Project
Fall 2014 Page 8 of 8 Juan López
Extra Credit #1 - Add option to Remove an exam grade from student Value: 1 homework assignment
Add menu option: Remove an exam grade from a student When user selects to remove an exam grade from a student, the program prompts the user for the student’s id.
If there is no student with the ID entered, the program will let the user know, and then re- output the main menu.
If a student is found, the program will list all the grades associated with that student and prompt the user for the exam number to delete:
Enter student ID: 1235 Student: Lopez, Jennifer =========== Num - Score =========== [ 0] - 94 [ 1] - 100 Enter Quiz number: 1 About to delete [ 1] - 100 Are you Sure? (y/n) y
After removing the grade, the program will print out the student’s record, confirming the exam score removal:
Grade [1] deleted: Student ID: 1235 Student Name: Lopez, Jennifer Year in School: 5 Grades: 94 Average: 94.00
Extra Credit #2 – When the user selects Quit, if he has made changes to the course and has not saved, prompt him to save changes. Value: 1 homework assignment Extra Credit #3 – Create a version of the program in another language. Value: 1 homework assignment