Hello all! i'm trying to complete the following Java programming assignment, which is late because it won't compile. The prof has not been helpful and the TA is nowhere to be found. I'm using two classes. For the life of me, I cannot figure out what is wrong. Please help! Here's the assignment:
Write a program with an array that is initialized with test data. Use any primitive data type of your choice. The program should also have the following methods:
• getTotal. This method should accept a one- dimensional array as its argument and return the total of the values in the array.
• getAverage. This method should accept a one- dimensional array as its argument and return the average of the values in the array.
• getHighest. This method should accept a one- dimensional array as its argument and return the highest value in the array.
• getLowest.
This method should accept a one- dimensional array as its argument and return the lowest value in the array. Demonstrate each of the methods in the program.
[java=highlight]
import javax.swing.JOptionPane;
public class TestScores
{
public static void main (String [] args)
{
double [] scores = { 100, 80, 85, 92, 95, 72, 59, 77, 96, 88 }; //Elements in array
//Create an array that holds ten test scores.
double [] scores = new double[scores];
//Get total of test scores
getValues(scores);
//Create TestData object and initialize it with test data.
TestData total = new TestData(scores);
//Display the following test data: total of test scores,
//average score, highest score, lowest score.
JOptionPane.showmessageDialog(null,
"The total of all test scores is " +
scores.getTotal() +
"/nThe average test score is " +
scores.getAverage() +
"/nThe highest test score is " +
scores.getHighest() +
"nThe lowest test score is " +
scores.getLowest());
System.exit(0);
}
}
public class TestData
{
private double [] scores; //The test data
/**A constructor that copies the array elements
* to the tests array.
@param s Array elements copied.*/
public TestData(double [] s)
{
//Create an array the same size as s.
scores = new double[s.length];
//Copy the array elements from s to tests.
for (int index = 0; index < s.length; index ++)
scores[index] = s[index];
}
/**getTotal method
* @return The total of test scores in the array.*/
public double getTotal()
{
int total = 0; //Initialize the accumulator
//Accumulate the sum of the test scores in the array.
for (int index = 0; index < scores.length; index++)
total += scores[index];
//Return total
return total;
}
/** getAverage method
* @return The average of all test scores in the array.
*/
public double getAverage()
{
return getTotal()/(scores.length);
}
/**getHighest method
* @return the highest value test score in the array.
*/
public double getHighest()
{
double highest = scores[0];
for (int index = 1; index < scores.length; index++)
{
if (scores[index] > highest);
highest = scores[index];
}
return highest;
}
/**getLowest method
* @return The lowest test score in the array.
*/
public double getLowest()
{
double lowest = scores[0];
for (int index = 1; index < scores.length; index++)
{
if (scores[index] < lowest)
lowest = scores[index];
}
return lowest;
}
}