Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create program in java. 5. Create an Exam Results class that has four instance m

ID: 654014 • Letter: C

Question

Create program in java.

5. Create an Exam Results class that has four instance methods: record, average, max, mm, and count. record enters a grade (an integer between 0 and 100). average, max) mm, and count report on the grades entered so far, average, min, and count return the average, minimum, and maximum grades, respectively. count returns the number of grades entered. record should perform an integrity check on the grade it is should check that the grade is between 0 and 100). Write a program to test assume grades are integers. However, average should return the average value.

Explanation / Answer

import java.util.*;

class ExamResults

{

int noofgrades=0;

int sumofgrades=0;

int grade;

int min=101;

int max=0;

public void record(int igrade)

{

if (igrade >=0 && igrade <=100)

{

grade=igrade;

sumofgrades= sumofgrades + grade;

noofgrades++;

}

}

public double average()

{

return sumofgrades/noofgrades;

}

public int count()

{

return noofgrades;

}

public int min()

{

if (min > grade)

min=grade;

return min;

}

public int max()

{

if (max < grade)

max=grade;

return max;

}

}

public class Results

{

public static void main(String[] args)

{

ExamResults ee = new ExamResults();

int input=0;

Scanner in = new Scanner(System.in);

System.out.println("Enter the grades :(-1 to stop)");

while(input!=-1)

{

input=in.nextInt();

ee.record(input);

}

System.out.println("No. of grades : " + ee.count());

System.out.println("Average grade : " + ee.average());

System.out.println("Min grade : " + ee.min());

System.out.println("Max grade : " + ee.max());

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote