-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsing.java
More file actions
115 lines (104 loc) · 4.1 KB
/
parsing.java
File metadata and controls
115 lines (104 loc) · 4.1 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class parsing {
private static String comDel = ",";
private static String userInput = "a";
public static void main(String[] args) {
List<List<String>> parentList = new ArrayList<>();
List<String> names = new ArrayList<>();
try (Scanner sc = new Scanner(new File("sample.csv"))) {
while (sc.hasNextLine()) {
parentList.add(addRows(sc.nextLine()));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for (List<String> fileName : parentList) {
names.add(fileName.get(1));
names.add(fileName.get(2));
}
androidDevs(parentList);
NameCounter(names, userInput);
TimeSamples(parentList, names);
}
public static List<String> addRows(String fileLine) {
// method that takes the fileinput and adds it to a List
List<String> lines = new ArrayList<String>();
try (Scanner scRows = new Scanner(fileLine)) {
scRows.useDelimiter(comDel);
while (scRows.hasNext()) {
lines.add(scRows.next());
}
}
return lines;
}
private static void androidDevs(List<List<String>> parentList) {
// method that checks the users that decides to develop for android
List<String> androids = new ArrayList<>();
int i = 0;
for (List<String> users : parentList) {
androids.add(users.get(6));
}
for (String android : androids) {
if (android.equals("Android App")) {
i++;
}
}
System.out.println(i + " has chosen to develope in Android");
}
private static void NameCounter(List<String> names, String userIn) {
// method to check howe many "A" there are in all the names
int nameCount = 0;
for (int i = 2; i < names.size(); i++) {
if (names.get(i).contains(userIn) || names.get(i).contains(userIn.toUpperCase())) {
nameCount++;
}
}
System.out.println(nameCount + " people has the letter " + userIn + " in them.");
}
public static void TimeSamples(List<List<String>> parentList, List<String> names) {
// method that checks the timespamps
// if there is instances where the same date occurs it prints it out
List<String> dateTime = new ArrayList<>();
List<String> uniqueDateTime = new ArrayList<>();
List<String> sameDateTime = new ArrayList<>();
List<String> namesOne = new ArrayList<>();
List<String> namesTwo = new ArrayList<>();
List<String> dateNames = new ArrayList<>();
int index = 0;
for (List<String> line : parentList) {
dateTime.add(line.get(0));
namesOne.add(line.get(1));
namesTwo.add(line.get(2));
if (dateTime.get(index).equals("")) {
uniqueDateTime.add(dateTime.get(index));
} else if (uniqueDateTime.contains(dateTime.get(index))) {
sameDateTime.add(dateTime.get(index));
} else {
uniqueDateTime.add(dateTime.get(index));
}
index++;
}
Boolean isTrue = true;
for (String x : sameDateTime) {
for (int i = 0; i < dateTime.size(); i++) {
if (x.equals(dateTime.get(i))) {
dateNames.add(namesOne.get(i));
dateNames.add(" and ");
dateNames.add(namesTwo.get(i));
if (isTrue) {
dateNames.add(x);
dateNames.add(" has the same timestamp as ");
isTrue = false;
}
}
}
isTrue = true;
System.out.println(dateNames);
dateNames.removeAll(dateNames);
}
}
}