0% found this document useful (0 votes)
32 views1 page

Exam Grades

This Java code defines an ExamGrades class that calculates statistics about student exam results. The class tracks the number of students, passing grade, total average score, number of students who passed, and average score of passing students. An object of this class can be created with the number of students and passing grade, and the statistics() method collects grades from the user and calculates the various statistics.

Uploaded by

Yair Haimi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Exam Grades

This Java code defines an ExamGrades class that calculates statistics about student exam results. The class tracks the number of students, passing grade, total average score, number of students who passed, and average score of passing students. An object of this class can be created with the number of students and passing grade, and the statistics() method collects grades from the user and calculates the various statistics.

Uploaded by

Yair Haimi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;
public class ExamGrades {
private int numOfStudents;
private int passGrade;
public int getNumOfStudents() {
return numOfStudents;
}
public void setNumOfStudents(int numOfStudents) {
this.numOfStudents = numOfStudents;
}
public int getPassGrade() {
return passGrade;
}
public void setPassGrade(int passGrade) {
this.passGrade = passGrade;
}
public ExamGrades(int numOfStudents, int passGrade) {
super();
this.numOfStudents = numOfStudents;
this.passGrade = passGrade;
}
public void statistics() {
Scanner s = new Scanner(System.in);
int studPass = 0;
int avg = 0;
int passAvg = 0;
int n = 0;
while (n < this.numOfStudents) {
System.out.println("Enter grade:");
int grade = s.nextInt();
if (grade >= this.passGrade) {
studPass++;
avg += grade;
passAvg += grade;
} else {
avg += grade;
}
}

n++;

passAvg = passAvg / studPass;


avg = avg / this.numOfStudents;
System.out.println("Total average: " + avg + "\n" + "Students that passed: " + studPass + "\n"
+ "Average of students that passed: " + passAvg);
}
public String toString() {
return "Number of students in the class: " + this.numOfStudents + "\n" + "Minimum passing grade: "
+ this.passGrade;
}
}

You might also like