I am having trouble getting output from this program. The objective of the program is to allow the user to enter 5 scores and then it is supposed to calculate the mean and rearrange the data set from highest to lowest.
I am supposed to run it through the AverageDriver class. The main method is only supposed to declare and instantiate an Average object. The Average object information should then be printed to the console. It should output the data set from highest to lowest and the mean.
Please help me find any mistakes I've been trying this for hours and I cant seem to figure it out. Any input would be greatly appreciated.
import java.util.Scanner;
public class Average
{
private int data[];
private double mean;
public Average()
{
//Create a Scanner object for keyboard input
Scanner keyboard = new Scanner(System.in);
final int SCORES = 5; //Total number of scores
//Create an array to hold scores entered by the user.
data = new int[SCORES];
System.out.println("Please enter the " + SCORES + " scores.");
//Cycle through the array, getting each score.
for (int i = 0; i < SCORES; i++)
{
System.out.println("Score " + (i + 1) + ": ");
data[i] = keyboard.nextInt();
}
calculateMean();
selectionSort();
}
public void calculateMean()
{
double total = 0;
for (int i = 0; i < data.length; i++)
total += data[i];
mean = (total / data.length);
}
public void selectionSort()
{
int highest = data[0];
for (int i = 1; i < data.length; i++)
{
if(data[i] > highest)
highest = data[i];
}
}
public String toString()
{
String str = ("Data: " + data + "\nMean: " + mean);
return str;
}
}
public class AverageDriver
{
public static void main(String[] args)
{
Average object = new Average();
object.toString();
}
}