-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistics.java
56 lines (40 loc) · 1.16 KB
/
statistics.java
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
package com.iot.climateedge.myapplication;
import java.util.Vector;
//class to decide statistics for the farmer from the sensor data.
//INPUTS:
// A vector of any type.
//METHODS:
//MIN: Finds the minimum element in a vector.
//MAX: Finds the maximum element in a vector.
//AVG: Finds the average of all the values in the vector.
public class statistics {
float min(Vector<Object> values){
float temp;
temp = (float)values.get(0);
for(int i = 0;i < values.size();i++){
if(temp < (float)values.get(i)){
temp = (float)values.get(i);
}
}
return temp;
}
float max(Vector<Object> values){
float temp;
temp = (float)values.get(0);
for(int i = 0;i < values.size();i++){
if(temp > (float)values.get(i)){
temp = (float)values.get(i);
}
}
return temp;
}
float avg(Vector<Object> values){
float sum = 0;
float average;
for(int i = 0;i < values.size();i++){
sum = sum + (float)values.get(i);
}
average = sum/values.size();
return average;
}
}