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

Based on the code below, please make a Javadocs(not generated by eclipse) that w

ID: 3833409 • Letter: B

Question

Based on the code below, please make a Javadocs(not generated by eclipse) that will describe each field and method of a class, its different from pseudo code, it should be a list that's written into a word document and numbered. Each method, attribute, etc should have a description underneath it and labeled by number, not comments in the code.

******************************************************************************************************************

public class InvalidTestScore extends Exception
{
//Constructor that takes double type score
//calls the super class Exception class
public InvalidTestScore(double badScores)
{
super("Error: Number cannot be less than 0 and greater than 100 i.e" + badScores);
}
}

*************************************************************************************************


public class TestScores
{
  
//Modify the data type of scores to double since
//from main method of the Chp12PC02 class , the passing
//array type is double
private final double scores[] = new double [5];
  
/**
* constructor
* @param badScores
* @throws chp12pc02.InvalidTestScore
* @throws InvalidTestScores
*/
//Modify the passing array type as double
public TestScores(double[] badScores) throws InvalidTestScore
{
// input for test score
  
for (int index = 0; index < 5; index++)
{
if (badScores[index] < 0 || badScores[index] > 100)
{
//throws an InvalidTestScore exception if score is less than
//0 or greater than 100
throw new InvalidTestScore(badScores[index]);
}
else
{
scores[index] = badScores[index];
//Do not call the average method from this position
}
}   
}

//Modify the name of the method getAverage since from
//main , the program calling as getAverage
public double getAverage()
{
//Modify the sum as double type
double sum = 0;
for(int index = 0; index < 5; index++)
{
sum += scores[index];
}
//return the average of the scores
return sum / 5;
}
}

********************************************************************************************

/**Modified java program TestScoresDemo to throws an InvalidTestScore
* exception if the score of the array is less than zero or greater
* than 100.*/
public class TestScoresDemo
{
public static void main(String[] args)
{
/**
* an array with test scores. notice that element 3 contains an
* invalid score
*/
  
//This array badScores contains an invalid score 101
double[] badScores = {97.5, 66.7, 88.0, 101.0, 99.0};
  
/**
* create a TestScores object initialized with badScores
*/
  
try
{
//The constructor in the class TestScores throws invalid Test score exception
//since 101 is greater than 100.
TestScores tBad = new TestScores(badScores);
// the following statement should not execute   
System.out.println("The average of the bad scores is " +
tBad.getAverage());
}
catch (InvalidTestScore e)
{
System.out.println("Invalid score found. " + e.getMessage());
}
  
  
/**
* array with test scores. all of these scores are good
*/
  
double[] goodScores = {97.5, 66.7, 88.0, 100.0, 99.0};
  
/**
* create a TestScores object initialized with goodScores
*/
  
try
{
//This constructor do not throw InvalidTestScore exception
//since the array goodScores do not contain any invalid score
TestScores tGood = new TestScores(goodScores);
System.out.println("The average of the good scores is " +
tGood.getAverage());
}
catch (InvalidTestScore e)
{
System.out.println("Invalid score found. " + e.getMessage());
}
}
}

Explanation / Answer

public class TestScoresDemo
{
public static void main(String[] args)
{
/**
* an array with test scores. notice that element 3 contains an
* invalid score
*/
  
//This array badScores contains an invalid score 101
double[] badScores = {97.5, 66.7, 88.0, 101.0, 99.0};
  
/**
* create a TestScores object initialized with badScores
*/
  
try
{
//The constructor in the class TestScores throws invalid Test score exception
//since 101 is greater than 100.
TestScores tBad = new TestScores(badScores);
// the following statement should not execute   
System.out.println("The average of the bad scores is " +
tBad.getAverage());
}
catch (InvalidTestScore e)
{
System.out.println("Invalid score found. " + e.getMessage());
}
  
  
/**
* array with test scores. all of these scores are good
*/
  
double[] goodScores = {97.5, 66.7, 88.0, 100.0, 99.0};
  
/**
* create a TestScores object initialized with goodScores
*/
  
try
{
//This constructor do not throw InvalidTestScore exception
//since the array goodScores do not contain any invalid score
TestScores tGood = new TestScores(goodScores);
System.out.println("The average of the good scores is " +
tGood.getAverage());
}
catch (InvalidTestScore e)
{
System.out.println("Invalid score found. " + e.getMessage());
}
}
}

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