-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment.java
More file actions
83 lines (63 loc) · 2.46 KB
/
Assignment.java
File metadata and controls
83 lines (63 loc) · 2.46 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
/**
* Parsing Export Data
*
* @author Deny Kiantono
* @version 1.0
*/
import edu.duke.*;
import org.apache.commons.csv.*;
public class Assignment {
public String countryInfo(CSVParser parser, String country) {
for (CSVRecord record : parser) {
String currentCountry = record.get("Country");
if (currentCountry.equalsIgnoreCase(country)) {
String exports = record.get("Exports");
String value = record.get("Value (dollars)");
String result = currentCountry + ": " + exports + ": " + value;
return result;
}
}
return "NOT FOUND";
}
public void listExportersTwoProducts(CSVParser parser, String exportItem1, String exportItem2) {
for (CSVRecord record : parser) {
String exports = record.get("Exports");
if (exports.contains(exportItem1) && exports.contains(exportItem2)) {
String country = record.get("Country");
System.out.println(country);
}
}
}
public int numberOfExporters(CSVParser parser, String exportItem) {
int totalCountry = 0;
for (CSVRecord record : parser) {
String exports = record.get("Exports");
if (exports.contains(exportItem)) {
totalCountry++;
}
}
return totalCountry;
}
public void bigExporters(CSVParser parser, String amount) {
for (CSVRecord record : parser) {
String currentAmount = record.get("Value (dollars)");
if (currentAmount.length() > amount.length()) {
String country = record.get("Country");
System.out.println(country + " " + currentAmount);
}
}
}
public void tester() {
FileResource fr = new FileResource();
CSVParser parser = fr.getCSVParser();
System.out.println(countryInfo(parser, "Nauru"));
parser = fr.getCSVParser();
System.out.println("Both cotton anf flowers");
listExportersTwoProducts(parser, "cotton", "flowers");
parser = fr.getCSVParser();
System.out.println("cocoa");
System.out.println(numberOfExporters(parser, "cocoa"));
parser = fr.getCSVParser();
bigExporters(parser, "$999,999,999");
}
}