Guest User

Untitled

a guest
Feb 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import org.apache.commons.csv.*;
  2. /**
  3. * Write a description of CVSProject here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class JDsCSVProject {
  9.  
  10.  
  11. public class WhichCountriesExport {
  12. public void listExporters(CSVParser parser, String exportOfInterest) {
  13. //for each row in CSV File
  14. for (CSVRecord record : parser) {
  15. //look at the "Exports" column
  16. String export = record.get("Exports");
  17. //check if it contains exportOfInterest
  18. if (export.contains(exportOfInterest)) {
  19. //If so, write down the "Country" from that row
  20. String country = record.get("Country");
  21. System.out.println(country);
  22. }
  23. }
  24. }
  25. public void whoExportsCoffee() {
  26. FileResource fr = new FileResource();
  27. CSVParser parser= fr.getCSVParser();
  28. listExporters(parser, "fuel");
  29. public String countryInfo (CSVParser parser, String country) {
  30. //for every country in the CSV
  31. for (CSVRecord record : parser
  32. // if the country is not found
  33. String countries = record.get("Country")
  34. //if the country is found
  35. if (countries.contains(country)) {
  36. //get exports according country
  37. String exports = record.get("Exports")
  38. //get value of exports//
  39. String value = record.get("Value (dollars)");
  40. String countryInformation = country + ": " + exports + ": " + value;
  41.  
  42. return countryInformation;
  43. }
  44. //if country is not found
  45. String notFound = "NOT FOUND";
  46. return notFound
  47. }
  48. }
Add Comment
Please, Sign In to add comment