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

Can anyone help me write comments for this code. Fill this code with alot of use

ID: 673954 • Letter: C

Question

Can anyone help me write comments for this code. Fill this code with alot of useful comments. I will give you a thumbs up.

I need to write comments describing the functions for these two java files

TestScores.java

public class TestScores
{
private double scores[] = new double[5];
public TestScores (double test[])throws InvalidTestScores
{
for(int i=0;i<5;i++)
{
if(test[i]<0||test[i]>100)
{
throw new InvalidTestScores (test[i]);
}
else
{
scores[i]=test[i];
}
System.out.println("Average is:"+getAverage());
}
}

public double getAverage()
{
double sum=0;
double avg;
for(int i=0;i<5;i++)
{
sum+=scores[i];
}
avg=sum/5;
return avg;
}
}

InvalidTestScores.java

public class InvalidTestScores extends Exception
{
public InvalidTestScores(double n)
{
super ("Error:Number cannot be "
+ "less than 0 and greater than 100 i.e "+n);
}
  
}

Explanation / Answer

public class TestScores
{
private double scores[] = new double[5];//Declaring of scores array of double type
public TestScores (double test[])throws InvalidTestScores
{
for(int i=0;i<5;i++)
{
if(test[i]<0||test[i]>100)//checking the each value in array value based on index
{
throw new InvalidTestScores (test[i]);//If value is less than zero (or) greather than 100 throw the exception
}
else
{
scores[i]=test[i];// Inserting (or) pushing value from test array to scores array
}
System.out.println("Average is:"+getAverage());//Calculated average will print here
}
}
public double getAverage()
{
double sum=0;//Declaring double type varible as sum
double avg; //Declaring avg of type double
for(int i=0;i<5;i++)
{
sum+=scores[i];//adding each score array value to sum , here sum+ is short circuit operator it is alterative to sum=sum +value
}
avg=sum/5;//dividing value in sum by 5
return avg;//Returning value of avg from the function
}
}
InvalidTestScores.java
public class InvalidTestScores extends Exception // This class handles the exception caused in "TestScores.java"
{
public InvalidTestScores(double n)//If invalid value is existed that value passed into InvalidTestScores(double)
{
super ("Error:Number cannot be "
+ "less than 0 and greater than 100 i.e "+n);//This return an error that value and its statement.
}
  
}

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