Question: I keep on getting errors in my program. I don't know what I am doing wrong. Task #1 Average Class Create a class called Average

I keep on getting errors in my program. I don't know what I am doing wrong.

Task #1 Average Class

Create a class called Average according to the UML diagram.

Average

-data [ ] :int

-mean: double

+Average( ):

+calculateMean( ): void

+toString( ): String

+selectionSort( ): void

This class will allow a user to enter 5 scores into an array. It will then rearrange the data in descending order and calculate the mean for the data set.

Attributes: data[] the array which will contain the scores mean the arithmetic average of the scores Methods: Average The constructor.The constructor will then call the selectionSort and the calculateMean methods. calculateMean this is a method that uses a for loop to access each score in the array and add it to a running total. The total divided by the number of scores (use the length of the array), and the result is stored into the mean. toString returns a String containing data in descending order and the mean. selectionSort this method uses the selection sort algorithm to rearrange the data set from highest to lowest.

class average { private int[] data; private double mean; average () { this.data= new int[5]; this.mean=0; Scanner keyboard = new Scanner(System.in); for(int i=0; idata.length; i++){ total += data[i]; { mean= total/ (data.length); } public void selectionSort() { int maxIndex; int maxValue; for (int i=0; i maxValue) { maxValue=data[index]; maxIndex=index; } } data[maxIndex]=data[i]; data[i]=maxValue; } } public String toString() { System.out.println("The tests scores are:"); for (int i = 0; i < data.length; i++) System.out.print(data[i] + " "); System.out.println("Average is: ")+ mean; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!