Create within java. Include a program that tests the ExamResults class. Create a
ID: 653893 • Letter: C
Question
Create within java.
Include a program that tests the ExamResults class.
Create an ExamResults class that has four instance methods: record, average, max, min, 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 javax.swing.JOptionPane;
public class ExamAnalysis
{
public static void main( String args[] )
{
// initializing variables in declarations
int passes = 0, // number of passes
failures = 0, // number of failures
student = 1, // student counter
result; // one exam result
String input, // user-entered value
output; // output string
// process 10 students; counter-controlled loop
while ( student <= 10 )
{
input = JOptionPane.showInputDialog( "Enter result (1=pass,2=fail)" );
result = Integer.parseInt( input );
if ( result == 1 )
passes = passes + 1;
else
failures = failures + 1;
student = student + 1;
}
// termination phase
output = "Passed: " + passes + " Failed: " + failures;
if( passes > 8 )
output = output + " Raise Tuition";
JOptionPane.showMessageDialog( null, output, "Analysis of Examination Results", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.