-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyticsCounter.java
More file actions
43 lines (37 loc) · 1.25 KB
/
AnalyticsCounter.java
File metadata and controls
43 lines (37 loc) · 1.25 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
package com.hemebiotech.analytics;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
public class AnalyticsCounter {
private static int headacheCount = 0; // initialize to 0
private static int rashCount = 0; // initialize to 0
private static int pupilCount = 0; // initialize to 0
public static void main(String args[]) throws Exception {
// first get input
BufferedReader reader = new BufferedReader (new FileReader("symptoms.txt"));
String line = reader.readLine();
int i = 0; // set i to 0
int headCount = 0; // counts headaches
while (line != null) {
i++; // increment i
System.out.println("symptom from file: " + line);
if (line.equals("headache")) {
headCount++;
System.out.println("number of headaches: " + headCount);
}
else if (line.equals("rush")) {
rashCount++;
}
else if (line.contains("pupils")) {
pupilCount++;
}
line = reader.readLine(); // get another symptom
}
// next generate output
FileWriter writer = new FileWriter ("result.out");
writer.write("headache: " + headacheCount + "\n");
writer.write("rash: " + rashCount + "\n");
writer.write("dialated pupils: " + pupilCount + "\n");
writer.close();
}
}