Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions feedback.txt
Original file line number Diff line number Diff line change
@@ -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?
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.
87 changes: 69 additions & 18 deletions src/main/java/codingcompetition2019/CodingCompCSVUtil.java
Original file line number Diff line number Diff line change
@@ -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<List<String>> readCSVFileByCountry(String fileName, String countryName) throws IOException {
// TODO implement this method
return null;
Scanner sc = new Scanner(new File(fileName));
List<List<String>> fin = new ArrayList<List<String>>();
while(sc.hasNextLine()) {
String line = sc.nextLine();
String[] ar = line.split(",");
if(ar[0].equals(countryName)) {
ArrayList<String> temp = new ArrayList<String>();
temp.add(line);
fin.add(temp);
}
}
sc.close();
return fin;
}

public List<List<String>> readCSVFileWithHeaders(String fileName) throws IOException {
// TODO implement this method
return null;
Scanner sc = new Scanner(new File(fileName));
List<List<String>> fin = new ArrayList<List<String>>();
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[]ar = line.split(",");
ArrayList<String> temp = new ArrayList<String>();
temp.add(line);
fin.add(temp);
}
sc.close();
return fin;
}

public List<List<String>> readCSVFileWithoutHeaders(String fileName) throws IOException {
// TODO implement this method
return null;
Scanner sc = new Scanner(new File(fileName));
sc.nextLine();
List<List<String>> fin = new ArrayList<List<String>>();
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[]ar = line.split(",");
ArrayList<String> temp = new ArrayList<String>();
temp.add(line);
fin.add(temp);
}
sc.close();
return fin;
}

public DisasterDescription getMostImpactfulYear(List<List<String>> records) {
// TODO implement this method
return null;
DisasterDescription dd = new DisasterDescription(records);
return dd;
}

public DisasterDescription getMostImpactfulYearByCategory(String category, List<List<String>> records) {
// TODO implement this method
return null;
DisasterDescription dd = new DisasterDescription(records);
dd.setYearByCategory(category);
return dd;
}

public DisasterDescription getMostImpactfulDisasterByYear(String year, List<List<String>> records) {
// TODO implement this method
return null;
DisasterDescription dd = new DisasterDescription(records);
dd.setDisasterByYear(year);
return dd;
}

public DisasterDescription getTotalReportedIncidentsByCategory(String category, List<List<String>> records) {
// TODO implement this method
return null;
DisasterDescription dd = new DisasterDescription(records);
dd.addUpIncedentsByCategory(category);
return dd;
}

/**
Expand All @@ -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<List<String>> 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<List<String>> records1, List<List<String>> records2) {
// TODO implement this method
return false;
DisasterDescription dd1 = new DisasterDescription(records1);
DisasterDescription dd2 = new DisasterDescription(records2);
return dd1.getReportedIncidentsNum() > dd2.getReportedIncidentsNum();
}
}
101 changes: 100 additions & 1 deletion src/main/java/codingcompetition2019/DisasterDescription.java
Original file line number Diff line number Diff line change
@@ -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<List<String>> records;


public DisasterDescription(List<List<String>> 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;
}

}