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
32 changes: 32 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>2019-StateFarm-CodingCompetitionProblem</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
5 changes: 5 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
8 changes: 8 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
16 changes: 11 additions & 5 deletions feedback.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Your team (name of each individual participating):
How many JUnits were you able to get to pass?
Your team (name of each individual participating): Alex Kim and Ethan Xie
How many JUnits were you able to get to pass? 10/10

Document and describe any enhancements included to help the judges properly grade your submission.
Step 1:
Step 2:
1: JavaDocs
2: Created PNG utilizing R to generate visualizations for the data easy for many people to understand. Found in src/main/resources/datagraphics
3: Created GUI in Gui.java for the user to utilize the CSV Utility. In order to open and access the GUI, run the main method in Gui.java.
In the GUI you will be able to select the data source and what method you wish to run on it. Based on this, it will show a parameter box which has
what it type of parameter it is expecting (there is a tooltip if you hover over it as well).
Based on the parameters given, method chosen, and data set, it will output the information that the user requested.


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?
Loved it, but perhaps maybe more guidance/instruction on what exactly each method should do or give a more detailled background on the context of the programming.
232 changes: 202 additions & 30 deletions src/main/java/codingcompetition2019/CodingCompCSVUtil.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,230 @@
package codingcompetition2019;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;

/**
* Utility class to parse through natural disaster data in CSV file format
* @author --
* @version 1.42
*/
public class CodingCompCSVUtil {

/**
* Parses through file passed in and filters only for natural disasters occurring in the specified country
* @param fileName path to the csv data file
* @param countryName name of the country to be filtered by
* @return a list of natural disasters found in the data file occurring in the specified country
* @throws IOException if the file is not found or cannot be parsed
*/
public List<List<String>> readCSVFileByCountry(String fileName, String countryName) throws IOException {
// TODO implement this method
return null;
List<List<String>> disasters = new ArrayList<List<String>>();
try {
String line;
BufferedReader br = new BufferedReader(new FileReader(fileName));
while ((line = br.readLine()) != null) {
String[] lineArr = line.split(",");
if(lineArr[0].contentEquals(countryName)) { //country is equal
disasters.add(new ArrayList<String>()); //add new row
for(String str : lineArr) {
disasters.get(disasters.size()-1).add(str);
}
}
}
br.close();
}
catch (IOException e) {
throw e;
}
return disasters;
}

/**
* Reads a CSV file with headers (reads in the first line)
* @param fileName path to the csv data file
* @return a 2D String arrayList representing the csv file including the first line (headers)
* @throws IOException if the file is not found or cannot be parsed
*/
public List<List<String>> readCSVFileWithHeaders(String fileName) throws IOException {
// TODO implement this method
return null;

List<List<String>> disasters = new ArrayList<List<String>>();
try {
String line;
BufferedReader br = new BufferedReader(new FileReader(fileName));
while ((line = br.readLine()) != null) {
String[] lineArr = line.split(",");
disasters.add(new ArrayList<String>()); //add new row
for(String str : lineArr) {
disasters.get(disasters.size()-1).add(str);
}

}
br.close();
}
catch (IOException e) {
throw e;
}
return disasters;
}

/**
* Reads a CSV file without the headers (ignores the first line)
* @param fileName path to the csv file
* @return a 2D String arrayList representing the csv file excluding the first line (headers)
* @throws IOException if the file is not found or cannot be parsed
*/
public List<List<String>> readCSVFileWithoutHeaders(String fileName) throws IOException {
// TODO implement this method
return null;

List<List<String>> disasters = new ArrayList<List<String>>();
try {
String line;
BufferedReader br = new BufferedReader(new FileReader(fileName));
br.readLine(); //skip the header line

while ((line = br.readLine()) != null) {
String[] lineArr = line.split(",");
disasters.add(new ArrayList<String>()); //add new row
for(String str : lineArr) {
disasters.get(disasters.size()-1).add(str);
}

}
br.close();
}
catch (IOException e) {
throw e;
}
return disasters;
}

/**
* Parses natural disaster data to find the year with the most natural disasters
* @param records 2D List representing the natural disaster data
* @return a DisasterDescription object with both the year with the most disasters and how many there were
*/
public DisasterDescription getMostImpactfulYear(List<List<String>> records) {
// TODO implement this method
return null;
}
Map<Integer, Integer> map = new HashMap<Integer,Integer>();
for(List<String> line : records) {
if(line.get(0).equals("All natural disasters")) {
continue; //don't need these
}
int year = Integer.parseInt(line.get(2));
int numDisasters = Integer.parseInt(line.get(3));
if(map.get(year)==null) {
map.put(year, numDisasters);

} else {
map.put(year, map.get(year)+ numDisasters);
}
}
int maxYear = 0;
int maxDisasters = -1;
for(Integer key : map.keySet()) {
if(map.get(key) >= maxDisasters) {
maxDisasters = map.get(key);
maxYear = key;
}
}
return new DisasterDescription(maxYear,"",maxDisasters);
}
/**
* Parses natural disaster data to find the year with the most natural disasters of a certain category/type
* @param category the category or type of natural disaster
* @param records the 2D list representing the natural disaster data
* @return a DisasterDescription object with both the year with the most disasters given the category and how many there were
*/
public DisasterDescription getMostImpactfulYearByCategory(String category, List<List<String>> records) {
// TODO implement this method
return null;
for(int i = 0; i < records.size(); i ++) {
if(!records.get(i).get(0).equals(category)) {
records.remove(i);
i--;
}
}
return(getMostImpactfulYear(records));
}


/**
* Parses natural disaster data to find the most frequent type of natural disaster in a given year
* @param year the year to be specified
* @param records the 2D list representing the natural disaster data
* @return a DisasterDescription object with both the category/type of the most frequent natural disaster in that year and how many times it occured in that year
*/
public DisasterDescription getMostImpactfulDisasterByYear(String year, List<List<String>> records) {
// TODO implement this method
return null;
for(int i = 0; i < records.size(); i ++) {
if(!records.get(i).get(2).contentEquals(year)) {
records.remove(i--);

}
}
for(int i = 0; i < records.size(); i ++) {
if(records.get(i).get(0).equalsIgnoreCase("All natural disasters")) {
records.remove(i--);
}
}
String category = "";
int max = 0;
int amountOfIncidents = 0;
for(int i = 0; i < records.size(); i ++) {
if(Integer.parseInt(records.get(i).get(3)) > max) {
max = Integer.parseInt(records.get(i).get(3));
category = records.get(i).get(0);
amountOfIncidents = Integer.parseInt(records.get(i).get(3));
}
}
return new DisasterDescription(Integer.parseInt(year), category, amountOfIncidents);

}


/**
* Parses natural disaster data to find how many reported incidents of a given type of natural disaster there were within a data set
* @param category the category/type of natural disaster to be counted/searched for
* @param records the 2D list representing the natural disaster data
* @return a DisasterDescription object containing the category and the amount that type of disaster occurred throughout the entire data set
*/
public DisasterDescription getTotalReportedIncidentsByCategory(String category, List<List<String>> records) {
// TODO implement this method
return null;
for(int i = 0; i < records.size(); i ++) {
if(!records.get(i).get(0).equalsIgnoreCase(category)) {
records.remove(i--);
}
}
int count = 0;
for(int i = 0; i < records.size(); i ++) {
count += Integer.parseInt(records.get(i).get(3));
}
return(new DisasterDescription(0, category, count));
}

/**
* This method will return the count if the number of incident falls within the provided range.
* To simplify the problem, we assume:
* + A value of -1 is provided if the max range is NOT applicable.
* + A min value can be provided, without providing a max value (which then has to be -1 like indicated above).
* + If a max value is provided, then a max value is also needed.
* Finds the number of years that had a certain amount (range) of natural disasters occurring in that year throughout a natural disaster data set
* @param records the 2D list representing the natural disaster data
* @param min the lower bound of the disaster frequency range for a year to be counted
* @param max the upper bound of the disaster frequency range for a year to be counted. -1 if no max is specified
* @return the number of years with number of disasters within the specified range
*/
public int countImpactfulYearsWithReportedIncidentsWithinRange(List<List<String>> records, int min, int max) {
// TODO implement this method
return -1;
int count = 0;
if(max == -1) {
max = Integer.MAX_VALUE;
}
for(int i = 0; i < records.size(); i ++) {
int incidentAmountPerYear = Integer.parseInt(records.get(i).get(3));
if(incidentAmountPerYear >= min && incidentAmountPerYear <= max) {
count++;
}
}
return count;
}

/**
* @param records1 the 2D list representing the first set of natural disaster data
* @param records2 the 2D list representing the second set of natural disaster data
* @return true if the first set of data has more natural disasters than the second. False otherwise.
*/
public boolean firstRecordsHaveMoreReportedIndicents(List<List<String>> records1, List<List<String>> records2) {
// TODO implement this method
return false;
return records1.size() > records2.size();
}


}
Loading