Create within java Create an Exam Results class that has four instance methods:
ID: 653817 • Letter: C
Question
Create within java
Create an Exam Results class that has four instance methods: record, average, maximum, and count. record enters a grade (an integer between 0 and 100). average, max, min, 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 passed (it should check that the grade is between 0 and 100). Write a program to test your class. Assume grades are integers. However, average should return the average grade as a double value.Explanation / Answer
import java.util.*;
import java.io.*;
class ExamResults
{
public static int grade[]=new int[10];
public static count_g=0;
public static void main(String args[])
{
record();
max();
min();
average();
count();
}
public static void record()
{
int i;
Scanner console = new Scanner(System.in);
// Here the values are accepted from the user
for(i=0;i<10;i++)
{
System.out.println("Enter the grade of Student:");
//Here is were all the storing is done
grade[i]=console.nextInt();
//Here is my check values for the inputted Grades
if(grade[i]<0 || grade[i]>100)
{
System.out.println("You did not enter a valid Grade.");
--grade[i];
}//if
else
{
count_g++;
System.out.println("Thanks for entering the Grade " + grade[i]);
}//else
}//for
} //record
public static void max()
{
int maximum;
maximum=grade[0];
for(int i=0;i<10;i++)
{
if(maximum<grade[i])
{
maximum=grade[i];
}
}
System.out.println(" Maximum Grade="+maximum);
}
public static void min()
{
int minimum;
minimum=grade[0];
for(int i=0;i<10;i++)
{
if(minimum>grade[i])
{
minimum=grade[i];
}
}
System.out.println(" Minimum Grade="+minimum);
}
public static void average()
{
int avg;
int sum=0;
for(int i=0;i<10;i++)
{
sum=sum+grade[i];
avg=sum/10;
}
System.out.println(" Average Grade="+avg);
}
public static void count()
{
System.out.println(" Grade Count="+count_g);
}
}//Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.