Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions

Question

b. Where did they come from?

Answered: 1 week ago

Question

What is order of reaction? Explain with example?

Answered: 1 week ago

Question

Derive expressions for the rates of forward and reverse reactions?

Answered: 1 week ago