-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataAnalysis.java
41 lines (31 loc) · 1.11 KB
/
DataAnalysis.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
import java.util.Scanner;
import java.util.ArrayList;
public class DataAnalysis {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String mode = "";
while(!mode.toLowerCase().equals("sum") && !mode.toLowerCase().equals("avg")){
System.out.println("Please enter an analysis type: sum or avg");
mode = sc.nextLine();
}
ArrayList<Double> dataPoints = new ArrayList<Double>();
String in = "";
System.out.println("Please enter your data. When you are done, type \"done\".");
while(true){
in = sc.nextLine();
if(in.toLowerCase().equals("done")) break;
dataPoints.add(Double.parseDouble(in));
}
double sum = 0;
for(Double d : dataPoints){
sum += d;
}
if(mode.equals("sum")){
System.out.println("The sum of your data is: " + sum);
}
if(mode.equals("avg")){
System.out.println("The average of your data is: " + (sum / dataPoints.size()));
}
sc.close();
}
}