Question

IN JAVA (ECLIPSE) Design a TestScores class that has fields to hold three test scores. (If...

IN JAVA (ECLIPSE)

Design a TestScores class that has fields to hold three test scores. (If you have already written the TestScores class for programming challenge 8 of chapter 3, you can modify it.) the class constructor should accept three test scores as arguments and assign these arguments to the test score fields. The class should also have accessor methods for the test score fields, a method that returns the average of the test scores, and a method that returns the letter grade the is assigned for the test score average. Use the grading scheme in the following table:  

Test Score Average: Letter Grade:
90-100 A
80-89 B
70-79 C
60-69 D
below 60 F

*Extra Needs: *

Use JOptionPane for I/O. Use constants where appropriate.

You should have a TestScores.java and a testing class that houses your main. *

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

import javax.swing.JOptionPane;

class TestScores{
   private int score1;
   private int score2;
   private int score3;
   private static final String GRADE_A="A";
   private static final String GRADE_B="B";
   private static final String GRADE_C="C";
   private static final String GRADE_D="D";
   private static final String GRADE_F="F";
  
   public TestScores(int aScore1, int aScore2, int aScore3) {
       super();
       score1 = aScore1;
       score2 = aScore2;
       score3 = aScore3;
   }
   public int getScore1() {
       return score1;
   }
   public void setScore1(int aScore1) {
       score1 = aScore1;
   }
   public int getScore2() {
       return score2;
   }
   public void setScore2(int aScore2) {
       score2 = aScore2;
   }
   public int getScore3() {
       return score3;
   }
   public void setScore3(int aScore3) {
       score3 = aScore3;
   }
   // function calculates average of scores
   public double average(){
       return (getScore1()+getScore2()+getScore3())/3.0;
   }
   public String grade(){
       double avg=average();
       if(avg>=90)
           return GRADE_A;
       if(avg>=80)
           return GRADE_B;
       if(avg>=70)
           return GRADE_C;
       if(avg>=60)
           return GRADE_D;
       return GRADE_F;
   }
}
public class TestScoresDriver {
public static void main(String[] args) {
   // creating instance
   Scanner sc = new Scanner(System.in);
   System.out.println("Enter 3 scores: ");
   int s1=Integer.parseInt(JOptionPane.showInputDialog("Enter score1"));
   int s2=Integer.parseInt(JOptionPane.showInputDialog("Enter score2"));
   int s3=Integer.parseInt(JOptionPane.showInputDialog("Enter score3"));
   TestScores t1 = new TestScores(s1,s2,s3);
   System.out.println("Average : "+t1.average());
   System.out.println("Grade: "+t1.grade());
  
}
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
IN JAVA (ECLIPSE) Design a TestScores class that has fields to hold three test scores. (If...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class named TestScores. The class constructor should accept an array of test scores as...

    Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to be...

  • Test Scores and Grade Write a program that has variables to hold three test scores. The...

    Test Scores and Grade Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test scores and the letter grade that is assigned for the test score average. Use the grading scheme in the following table: Test Score Average Letter Grade 90–100 A 80–89 B 70–79 C 60–69 D Below 60...

  • Write a class named TestScores. The class constructor should accept an array test scores as its...

    Write a class named TestScores. The class constructor should accept an array test scores as its argument. The class should a method that returns the average of the test scores. If any test score is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate this with an array of five items. This is JAVA program.

  • Write a grading program in Java for a class with the following grading policies: There are...

    Write a grading program in Java for a class with the following grading policies: There are three quizzes, each graded on the basis of 10 points. There is one midterm exam, graded on the basis of 100 points. There is one final exam, graded on the basis of 100 points. The final exam counts for 40% of the grade. The midterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade....

  • Write a program that asks the user to enter five test scores. The program should display...

    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage—This function should accept five test scores as arguments and return the average of the scores. determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale: Score Letter Grade...

  • Design a function named max that accepts two integer values as arguments and returns the value...

    Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Need Variable lists, Psuedocode, ipo chart, Flow Chart, and a python...

  • Write a javascript program that asks the user to enter five test scores. The program should...

    Write a javascript program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage—This method should accept five test scores as arguments and return the average of the scores. determineGrade—This method should accept a test score as an argument and return a letter grade for the score,

  • Write a program that asks the user to enter five test scores. The program should display...

    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage—This function should accept five test scores as arguments and return the average of the scores. determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale: Round the average...

  • Solve This Problem using python and please comment on every line. also, use function to solve...

    Solve This Problem using python and please comment on every line. also, use function to solve this. thanks The result will be like as below: Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following functions in the program: This function should accept five test scores as arguments and return the average of the scores. This function should accept a...

  • In Java, write a class Grade with following member variables and method: int midtermExam, int finalExam:...

    In Java, write a class Grade with following member variables and method: int midtermExam, int finalExam: represent the scores of midterm and final exams respectively. The maximum score for each exam is 100. double getOverallScore(): returns the overall score calculated as follows: 40% midterm and 60% final. Write another class Grade180 that is a subclass of Grade and has the following member variables and method: int midtermExam, int finalExam: inherited from Grade super class. int hw1, int hw2, int project1,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT