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

Hello, I need some help with this: The question says: (I\'m using the book \"ISB

ID: 3771043 • Letter: H

Question

Hello, I need some help with this:

The question says: (I'm using the book "ISBN: 978-0-13-377674-4" Chapter 10- Programming challenge 1.

Write a class named test scores. The class constructor should accept an array of test scores as its arguments. 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 IligalArgumentException, Demostrate the class in a program file.

----------------------------------------------------------------------------------------

If I have to create a file please tell me how, I'm using eclipse :)

Thanks!

Explanation / Answer

import java.util.Scanner; //import utility scanner for getting input from user public class TestScoresMain { public static void main(String[] args) {//Begin definition for main method //program variables double[] grades; double scoreAverage; grades = new double[2]; Scanner scan = new Scanner(System.in);//create new scanner object for grabbing input from user System.out.print("How many scores: ");//Ask the user how many scores they want to input int nb = scan.nextInt();//scan the input to find the number the user typed double[] scores = new double[nb]; //declare and initialize scores with length of nb for(int i = 0; i 100.0, an invalid entry { System.out.println("Invalid entry detected! Number must be between 0 and 100."); } TestScores testScores = new TestScores(grades); scoreAverage = testScores.getAverage(); System.out.println("The average score is: " +scoreAverage); } } import java.lang.IllegalArgumentException; //declare and initialize public class TestScores public class TestScores {//begin class definition // ************ declare and init vars *********** double average; //declare double variable: average double[] scoresAR;//declare double data-type array: scoresAR /** * Constructor * @param double[] scores - scores from TestScores class */ public TestScores(double[] scores) {//begin class definition this.scoresAR = scores;//set scoresAR to the passed value of scores double total = 0.0;//declare and initialize total as 0.0 for(int i = 0; i
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