Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Average
- {
- // an array to hold 5 interger values
- private int[] data = new int[5];
- // the average of the data in the array
- private double mean;
- /**
- * This constructor sets up the array and calls the
- * selectionSort and calculateMean methods
- */
- public Average()
- {
- Scanner keyboard = new Scanner(System.in);
- for (int i = 0; i < data.length; ++i)
- {
- System.out.println("Please enter an integer value:");
- data[i] = keyboard.nextInt();
- }
- selectionSort();
- calculateMean();
- }
- /**
- * This method calculates the mean of the data stored in the array
- */
- public void calculateMean()
- {
- //Put your code here for calculating the mean of all the
- //elements in the data array.
- //I NEED THIS*****
- }
- /**
- * This method returns the data in the array in descending order and the
- * mean
- *
- * @return value stored in b and mean
- */
- public String toString()
- {
- String b = " ";
- for (int i = 0; i < data.length; ++i)
- {
- b += " " + data[i];
- }
- return "The numbers in the array are:" + b + " and the mean is: " + mean;
- }
- /**
- * This method sorts data in array from highest to lowest
- */
- public void selectionSort()
- {
- int maxIndex;
- int maxValue;
- for (int startScan = 0; startScan < data.length - 1; startScan++)
- {
- maxIndex = startScan;
- maxValue = data[startScan];
- for (int index = startScan + 1; index < data.length; index++)
- {
- if (data[index] > maxValue)
- {
- maxValue = data[index];
- maxIndex = index;
- }
- }
- data[maxIndex] = data[startScan];
- data[startScan] = maxValue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement