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

Design a TestScores class that has fields to hold three test scores. The class s

ID: 3761400 • Letter: D

Question

Design a TestScores class that has fields to hold three test scores. The class should have a constructor, accessor and mutator methods for the lest score fields, and a method that returns the average of the test scores. Demonstrate the class by writing a separate program that creates an instance of the class. The program should ask the user to enter three test scores, which are stored in the TestScores object. Then the program should display the average of the scores, as reported by the TestScores object.

Explanation / Answer

import java.util.Scanner;


public class Main {


public static class Payroll{
private double test1,test2,test3;

public Payroll() {
}

public double getTest1() {
return test1;
}

public void setTest1(double test1) {
this.test1 = test1;
}

public double getTest2() {
return test2;
}

public void setTest2(double test2) {
this.test2 = test2;
}

public double getTest3() {
return test3;
}

public void setTest3(double test3) {
this.test3 = test3;
}
public double average(){
return ((test1+test2+test3)/3);
}
}
public static void main(String[] args) {
// TODO code application logic here
Payroll TestScores=new Payroll();
Scanner in=new Scanner(System.in);
System.out.println("Enter Score for test1");
TestScores.setTest1(in.nextDouble());
System.out.println("Enter Score for test2");
TestScores.setTest2(in.nextDouble());
System.out.println("Enter Score for test3");
TestScores.setTest3(in.nextDouble());
System.out.println("Average is "+TestScores.average());

}

}