rite a Java program that creates a grade book for a class. The program should be
ID: 3720266 • Letter: R
Question
rite a Java program that creates a grade book for a class. The program should be able to display all grades for a given student. It should allow the instructor to add a new grade (such as “Homework 4: 100”) or modify an existing grade.
Project Requirements:
The database has one table called Student.
The student table has 3 attributes
Student name – varchar(50)
Student id - int
Assignment – varchar (50)
Grade int
Optional – Create two tables. Student and Assignment
This option will require writing joins to access the DB data.
Student table attributes
Student name – varchar(50)
Student id - int
Assignment table attribute
sid – int (foreign key to Student table)
Assignment – varchar (50)
Grade int
Create a CreateGradeBook database in derby. Use the CreateDB example in the book as your guide. Once created the DB should persist. If built in the classroom, it may not after reboot due to the Freeze program.
Create Student Class (make adjusted as needed if using two tables)
NOTE: All data must be retrieved from the database as needed, no use of Arrays, ArrayList or any other type of collection or storage construct is allowed.
Instance Variables
String: studentName
int: studentID
Static int: nextStudentID
Constructors – default and parameterize constructors
Accessor and mutator methods for Student’s name and id.
Methods
addGrade
Takes in two parameters
String assignment
int grade
Adds a grade to the db.
Each entry must include name, studentID, assignment and grade. (Make required modification if using two tables)
displayGrades
returns a String that list all the students grades
Example output is
Joe Smith ID#: 1234
Assignment
Grade
Homework 1
89
Project 2
97
Midterm 1
78
findGrade
Takes in Assignment text
Returns a nicely formatted String representing the assignment and grade.
If assignment not found return “Not Found”.
modifyGrade
Takes in Assignment text and new assignment grade
Changes that assignment grade.
calculateAvg – returns a double representing the average of all grades. Note all grades have the same weight.
GradeBookTester
Creates at least 4 Student objects.
Test all methods in the Student class.
Any output should be nicely formatted
No user input required, either hard code the input or use a file.
If a file is used include the file in your submission zip file.
Submission Requirements:
Your project must be submitted using the instructions below. Any submissions that do not follow the stated requirements will not be graded.
1. You should have 2 files for this assignment:
Student.java
GradeBookTester.java
Input file (optional)
Joe Smith ID#: 1234
Assignment
Grade
Homework 1
89
Project 2
97
Midterm 1
78
Explanation / Answer
CODE:
import java.util.Scanner;
public class GradeBook
{
private String name;
private double sum,grade,average;
private int count;
public GradeBook (String name)
{
this.name = name;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public String displayMessage()
{
String S = "Total of the " + count +
"grades entered is " + sum + " ";
S += "Class average is " + average;
return S;
}
public double determineClassAverage()
{
while (grade != -1)
{
Scanner scan = new Scanner (System.in);
System.out.print("Enter the grade or -1 to quit: ");
grade = scan.nextDouble();
if (grade != -1) {
sum += grade;
count++; }
}
average = sum / count;
return average;
}
}
public class GradeBookTest
{
public static void main (String[] args)
{
double grade = 0; double sum = 0; int count = 0;
GradeBook grd1 = new GradeBook
("Introduction to Object Oriented Programming Csc 243 ");
System.out.println("Welcome to the Grade book for ");
System.out.println(grd1.getName());
System.out.println();
grd1.determineClassAverage();
System.out.println();
System.out.println(grd1.displayMessage());
}
}
OUTPUT:
Welcome to the Grade book for
Introduction to Object Oriented Programming Csc 243
Enter grade or -1 to quit: 97
Enter grade or -1 to quit: 88
Enter grade or -1 to quit: 72
Enter grade or -1 to quit: -1
Total of the 3 grades entered is 257
Class average is 85.65
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.