forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAverage.java
More file actions
71 lines (66 loc) · 1.65 KB
/
Average.java
File metadata and controls
71 lines (66 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.Scanner;
import java.util.Arrays;
/*
* 11/05/2015
_______________________________
+ AverageClass +
+______________________________
+ -int[]data +
+ -double: mean +
+______________________________
+ +Average(): +
+ +calculateMean():void +
+ +toString():String +
+ +selectionSort():void +
_______________________________
*/
public class Average
{
private int[] data = new int [5];
private double mean;
public Average()
{
for(int index=0; index<data.length; index++)
{
System.out.print("Enter a " +(index+1)+ " integer: ");
Scanner kb = new Scanner(System.in);
int inputVal = kb.nextInt();
data[index] = data[index] + inputVal;
}
selectionSort();
calculateMean();
}
public void calculateMean()
{
double total = 0;
for (int index=0; index<data.length; index++)
{
total = total + data[index];
}
mean = total/data.length;
}
public String toString()
{
String returnString = " ";
for (int i=data.length-1; i>=0; i--)
{
returnString += data[i]+ " ";
}
returnString = ("Scores: " + returnString + " \nAverage: " + mean);
return returnString;
}
public void selectionSort()
{
Arrays.sort(data);
int [] array = new int [5];
int j=0;
for(int i=data.length-1; i>=0; i--)
{
if (j<=5)
{
array[j] = data[i];
j++;
}
}
}
}