diff --git a/feedback.txt b/feedback.txt index 8234592..920dab6 100644 --- a/feedback.txt +++ b/feedback.txt @@ -1,9 +1,11 @@ -Your team (name of each individual participating): -How many JUnits were you able to get to pass? +Your team (name of each individual participating): Jacob Williams and Paul Cseley +How many JUnits were you able to get to pass? all 10 tests Document and describe any enhancements included to help the judges properly grade your submission. - Step 1: - Step 2: + Step 1: Alot of System.out.println() statments called and a couple left over + Step 2: just started storing data into the lists and parsing into Objects + Step 3: used my new Objects and methods to simplify more code -Feedback for the coding competition? Things you would like to see in future events? \ No newline at end of file +Feedback for the coding competition? Things you would like to see in future events? I enjoyed the events but I think +adding an instruction for the IDE and other applications before the start would be good. diff --git a/src/main/java/codingcompetition2019/CodingCompCSVUtil.java b/src/main/java/codingcompetition2019/CodingCompCSVUtil.java index 74f3074..811c56c 100644 --- a/src/main/java/codingcompetition2019/CodingCompCSVUtil.java +++ b/src/main/java/codingcompetition2019/CodingCompCSVUtil.java @@ -1,42 +1,78 @@ package codingcompetition2019; +import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; +import java.util.Scanner; public class CodingCompCSVUtil { public List> readCSVFileByCountry(String fileName, String countryName) throws IOException { - // TODO implement this method - return null; + Scanner sc = new Scanner(new File(fileName)); + List> fin = new ArrayList>(); + while(sc.hasNextLine()) { + String line = sc.nextLine(); + String[] ar = line.split(","); + if(ar[0].equals(countryName)) { + ArrayList temp = new ArrayList(); + temp.add(line); + fin.add(temp); + } + } + sc.close(); + return fin; } public List> readCSVFileWithHeaders(String fileName) throws IOException { - // TODO implement this method - return null; + Scanner sc = new Scanner(new File(fileName)); + List> fin = new ArrayList>(); + while (sc.hasNextLine()) { + String line = sc.nextLine(); + String[]ar = line.split(","); + ArrayList temp = new ArrayList(); + temp.add(line); + fin.add(temp); + } + sc.close(); + return fin; } public List> readCSVFileWithoutHeaders(String fileName) throws IOException { - // TODO implement this method - return null; + Scanner sc = new Scanner(new File(fileName)); + sc.nextLine(); + List> fin = new ArrayList>(); + while (sc.hasNextLine()) { + String line = sc.nextLine(); + String[]ar = line.split(","); + ArrayList temp = new ArrayList(); + temp.add(line); + fin.add(temp); + } + sc.close(); + return fin; } public DisasterDescription getMostImpactfulYear(List> records) { - // TODO implement this method - return null; + DisasterDescription dd = new DisasterDescription(records); + return dd; } public DisasterDescription getMostImpactfulYearByCategory(String category, List> records) { - // TODO implement this method - return null; + DisasterDescription dd = new DisasterDescription(records); + dd.setYearByCategory(category); + return dd; } public DisasterDescription getMostImpactfulDisasterByYear(String year, List> records) { - // TODO implement this method - return null; + DisasterDescription dd = new DisasterDescription(records); + dd.setDisasterByYear(year); + return dd; } public DisasterDescription getTotalReportedIncidentsByCategory(String category, List> records) { - // TODO implement this method - return null; + DisasterDescription dd = new DisasterDescription(records); + dd.addUpIncedentsByCategory(category); + return dd; } /** @@ -47,12 +83,27 @@ public DisasterDescription getTotalReportedIncidentsByCategory(String category, * + If a max value is provided, then a max value is also needed. */ public int countImpactfulYearsWithReportedIncidentsWithinRange(List> records, int min, int max) { - // TODO implement this method - return -1; + int inc = 0; + for(int i = 0; i < records.size();i++) { + String[] ar = records.get(i).get(0).split(","); + System.out.println(ar[0] + " "+ ar[3] +" " + records.size()); + if(max == -1) { + if(Integer.parseInt(ar[3]) >= min){ + inc += 1; + } + }else { + if(Integer.parseInt(ar[3]) >= min && Integer.parseInt(ar[3])<=max){ + inc += 1; + } + } + + } + return inc; } public boolean firstRecordsHaveMoreReportedIndicents(List> records1, List> records2) { - // TODO implement this method - return false; + DisasterDescription dd1 = new DisasterDescription(records1); + DisasterDescription dd2 = new DisasterDescription(records2); + return dd1.getReportedIncidentsNum() > dd2.getReportedIncidentsNum(); } } diff --git a/src/main/java/codingcompetition2019/DisasterDescription.java b/src/main/java/codingcompetition2019/DisasterDescription.java index 662626b..3a33a4f 100644 --- a/src/main/java/codingcompetition2019/DisasterDescription.java +++ b/src/main/java/codingcompetition2019/DisasterDescription.java @@ -1,5 +1,104 @@ package codingcompetition2019; +import java.util.List; + public class DisasterDescription { - // TODO finish this class + private String year; + private String disaster; + private int inc; + private List> records; + + + public DisasterDescription(List> records) { + this.records = records; + String year = ""; + int inc = 0; + for(int i = 0; i < records.size();i++) { + //System.out.println(records.get(i).get(0)+ " "+ i); + String[] ar = records.get(i).get(0).split(","); + if(ar.length == 4) { + if(Integer.parseInt(ar[3]) > inc){ + inc = Integer.parseInt(ar[3]); + year = ar[2]; + } + } + } + this.inc = inc; + this.year = year; + } + + public String getYear() { + return year; + } + + public void setYearByCategory(String category) { + String year = ""; + int inc = 0; + for(int i = 0; i < records.size();i++) { + //System.out.println(records.get(i).get(0)+ " "+ i); + String[] ar = records.get(i).get(0).split(","); + if(ar.length == 4) { + if(Integer.parseInt(ar[3]) > inc && ar[0].equals(category)){ + inc = Integer.parseInt(ar[3]); + year = ar[2]; + } + } + } + this.year = year; + } + + public void setDisasterByYear(String year) { + String disaster = ""; + int inc = 0; + for(int i = 0; i < records.size();i++) { + //System.out.println(records.get(i).get(0)+ " "+ i); + String[] ar = records.get(i).get(0).split(","); + if(!ar[0].equals("All natural disasters")) { + if(Integer.parseInt(ar[3]) > inc && ar[2].equals(year)){ + inc = Integer.parseInt(ar[3]); + disaster = ar[0]; + } + } + + } + this.inc = inc; + this.disaster = disaster; + } + + public String getCategory() { + return disaster; + } + + public int getReportedIncidentsNum() { + return inc; + } + + public void setIncByCategory(String category) { + int inc = 0; + for(int i = 0; i < records.size();i++) { + String[] ar = records.get(i).get(0).split(","); + if(!ar[0].equals("All natural disasters")) { + if(Integer.parseInt(ar[3]) > inc && ar[0].equals(category)){ + inc = Integer.parseInt(ar[3]); + } + } + + } + this.inc = inc; + } + + public void addUpIncedentsByCategory(String category) { + int inc = 0; + for(int i = 0; i < records.size();i++) { + String[] ar = records.get(i).get(0).split(","); + if(!ar[0].equals("All natural disasters")) { + if(ar[0].equals(category)){ + inc += Integer.parseInt(ar[3]); + } + } + + } + this.inc = inc; + } + }