-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParsingExportDataAssignment1.java
More file actions
67 lines (62 loc) · 2.27 KB
/
Copy pathParsingExportDataAssignment1.java
File metadata and controls
67 lines (62 loc) · 2.27 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
package CSVPractice;
import edu.duke.*;
import org.apache.commons.csv.*;
public class ParsingExportDataAssignment1 {
public String countryInfo(CSVParser parser, String country) {
String result = "";
for(CSVRecord record : parser) {
String countryCheck = record.get("Country");
String export = record.get("Exports");
String value = record.get("Value (dollars)");
if(countryCheck.contains(country)) {
result = country + ": " + export + ": " + value;
System.out.println(result);
} else {
result = "NOT FOUND";
}
}
return result;
}
public void listExportersTwoProducts(CSVParser parser, String exportItem1, String exportItem2) {
for(CSVRecord record : parser) {
String export = record.get("Exports");
if(export.contains(exportItem1) && export.contains(exportItem2)) {
String country = record.get("Country");
System.out.println(country);
}
}
}
public int numberOfExporters(CSVParser parser, String exportItem) {
int count = 0;
for(CSVRecord record : parser) {
String export = record.get("Exports");
if(export.contains(exportItem)) {
count ++;
}
}
System.out.println(count);
return count;
}
public String bigExporters(CSVParser parser, String amount) {
String bigExporters = "";
for(CSVRecord record : parser) {
String country = record.get("Country");
String value = record.get("Value (dollars)");
int valueNum = value.length();
int amountNum = amount.length();
if(valueNum > amountNum) {
bigExporters = country + " " + value;
System.out.println(bigExporters);
}
}
return bigExporters;
}
public void tester() {
FileResource fr = new FileResource();
CSVParser parser = fr.getCSVParser();
//countryInfo(parser, "Nauru");
//listExportersTwoProducts(parser, "fish", "nuts");
//numberOfExporters(parser, "sugar");
bigExporters(parser, "$999,999,999,999");
}
}