Question
I do not understand the difference between task 1 and task 2. Is it one code? or two separate codes? Here is what I have
I do not understand the difference between task 1 and task 2.
Is it one code? or two separate codes?
Here is what I have so far.
import java.util.Scanner;
public class Average { public static void main(String[] args) { Average average = new Average(); average.calculateMean(); average.selectionSort(); System.out.println(average.toString()); } private final int[] data; private double mean; private final int total = 0;
public Average() {
data = new int[5]; Scanner keyboard = new Scanner(System.in);
for(int i = 0; i
public void calculateMean() {
int i, s = 0; for(i = 0; i
mean = (double)s / (data.length);
}
public void selectionSort() { int maxIndex; int maxValue;
for(int startScan = 0; startScan maxValue) { maxValue = data[index]; maxIndex = index; } } data[maxIndex] = data[startScan]; data[startScan] = maxValue; } }
public String toString() { String output; output = "The test scores in descending order are ";
for(int i = 0; i
Task #1 Average Clas Create a class called Averageaccording to the UML diagram. Average -data [] int -mean: double +Average) +selection on( ): 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 dataI]-the array which will contain the scores mean the arithmetic average of the scores Methods Averagethe constructor. It will allocate memory for the array. It will then populate the array with 5 score entered by the user. Use a for loop to repeatedly display a prompt for the user which should ask the user to enter score number 1, score number 2, etc. Note: The computer starts counting with 0, but people start counting with 1, and your prompt should account for this. For example, when the user enters score number 1, it will be stored in indexed variable 0. 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 attribute mean selectionSort-this method uses the selection sort algorithm to rearrange the data set in array data from highest to lowest. toring-returns a String containing data in descending order and the mean
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started