In: Computer Science
Scenario
The instructors at the community college are happy with your grade averaging program and want to
expand it. You have been asked by the community college to modify the existing program to include
additional functionality that will calculate a student’s final grade for the faculty for multiple students.
The new program will accept data from the instructors, calculate the final grade and display information
on the screen. The program will output student information, the student category averages, the final
numeric grade and a statement that indicates if the student is passing.
Part I
1. Code the program using Java. The program should incorporate greetings to the instructor as well as
an ending message.
2. The program should include two classes: Grades.java and GradeCalculator.java.
3. The GradeCalculator.java class should include the main method and instantiate two objects
representative of two different sets of student grades. It should get input from the user and call
mutator and accessor methods to set and get object values.
4. The Grades.java class should include a constructor which will
a. initialize the Lab, Test and Project averages to a value of zero (0) and the final exm grade
to a value of zero (0) for each student grade object
b. keeps a running count of the number of students entered.
c. Records the system date the grades were entered for each student (Hint: use LocalDate class).
5. The program should greet the user by calling a method named displayGreeting();
6. The program should request the following information from the user:
Input Data (for each student):
7. The program should output the following information to the instructor by calling a method named
displayGrades() for each student:
Instructor receives the following output for each set of grades (one set for each student):
Example: (these are example values and should be output for both students)
Test Avg: 93.5
Lab Avg: 100
Project Avg: 93
Final Exm: 95
Course Grade: xx (weighted average calculated by the program)
Labs = 30%
Tests = 30%
Projects = 30%
Final Exm = 10%
Final Grade = 30% x lab average + 30% x test average + 30% x project
average + 10% x final exm
statement. Use the Boolean variable in a logical expression and print the result. Assume a 10
point scale when determining the passing rate.
8. Name the java class files Grades.java and GradeCalculator.java.
a. The GradeCalculator should include the main( ) method which instantiates objects, calls
methods to enter grades, get and set grades entered and displays information to the
instructor for each student.
b. The Grades class should include a constructor and methods to set and get values.
c. The calculations can be included in either the Grades or the GradeCalculator class. This can
be your decision.
We will create 2 classes namely
1. GradeCalculator (for calculating grades)
2. Grades (manage data of each student, set and get the grades)
We have created the class LocalData for storing the data of each student.
Now let us create a class Grade for which will set and get the grades of each student.
class Grade
{
String firstName;
String lastName;
int id;
double labAvg=0;
double projectAvg=0;
double testAvg=0;
double finalExam=0;
double finalGrade=0;
public Grade()
{
}
public Grade(String firstName,String lastName,int id,double labAvg,double projectAvg,double testAvg,double finalExam)
{
this.firstName=firstName;
this.lastName=lastName;
this.id=id;
this.labAvg=labAvg;
this.projectAvg=projectAvg;
this.testAvg=testAvg;
this.finalExam=finalExam;
finalGrade=((30*labAvg)/100) + ((30*testAvg)/100) + ((30*projectAvg)/100) + ((10*finalExam)/100);
}
public void displayGrades()
{
System.out.println("Name: "+firstName+" "+lastName);
System.out.println("Student ID: "+id);
System.out.println("Test Average: "+testAvg);
System.out.println("Lab Average: "+labAvg);
System.out.println("Project Average: "+projectAvg);
System.out.println("Final Exam: "+finalExam);
System.out.println("Final Grade: "+finalGrade);
System.out.println("-----------------------------");
}
}
Now we will create another class that is GradeCalculator which will be having the main function and will process the grade of students
import java.util.Scanner;
class GradeCalculator
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Total number of students: ");
int total=sc.nextInt();
int i=0;
Grade[] arr=new Grade[total];
while(total>0)
{
String firstName=sc.next();
String lastName=sc.next();
int id=sc.nextInt();
double labAvg=sc.nextDouble();
double projectAvg=sc.nextDouble();
double testAvg=sc.nextDouble();
double finalExam=sc.nextDouble();
arr[i] =new Grade(firstName,lastName,id,labAvg,projectAvg,testAvg,finalExam);
i++;
total--;
}
for(int i=0;i<total;i++)
{
arr[i].displayGrades();
}
}
}