diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/2023-StateFarm-CodingCompetition.iml b/.idea/2023-StateFarm-CodingCompetition.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/2023-StateFarm-CodingCompetition.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..6ff3c25
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..de88388
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FEEDBACK.md b/FEEDBACK.md
index 010fecd..aff5c5f 100644
--- a/FEEDBACK.md
+++ b/FEEDBACK.md
@@ -1,13 +1,16 @@
# Feedback
1. Your team:
-2. Name of each individual participating:
-3. How many unit tests were you able to pass?
+2. Name of each individual participating: Mahlangu Nzunda, Jaylon Nelson
+3. How many unit tests were you able to pass? All unit tests except for the last value for test #4
4. Document and describe any enhancements included to help the judges properly grade your submission.
- - Example One
+ - We had to change the data type of estimate cost for the claims Class from Float to Double because of accuracy errors for one of the tests
- Example Two
- Example Three
5. Any feedback for the coding competition? Things you would like to see in future events?
+Participating in this competition has been a wonderful learning experience for us.
+
+Having mentors to offer guidance and feedback on our implementations before we make the final submission would be really helpful for next. Additionally, it would be fantastic to gain exposure to cloud technologies, which are becoming increasingly important in software development.
This form can also be emailed to [codingcompetition@statefarm.com](mailto:codingcompetition@statefarm.com). Just make sure that you include a link to your GitHub pull requests.
diff --git a/java/.idea/.gitignore b/java/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/java/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/java/.idea/compiler.xml b/java/.idea/compiler.xml
new file mode 100644
index 0000000..3bc528e
--- /dev/null
+++ b/java/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/.idea/jarRepositories.xml b/java/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/java/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/.idea/misc.xml b/java/.idea/misc.xml
new file mode 100644
index 0000000..0abcc97
--- /dev/null
+++ b/java/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/.idea/vcs.xml b/java/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/java/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/Application.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/Application.java
index 1b2e64c..530e34b 100644
--- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/Application.java
+++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/Application.java
@@ -1,12 +1,15 @@
package com.statefarm.codingcompetition.simpledatatool;
import com.statefarm.codingcompetition.simpledatatool.controller.SimpleDataTool;
+import com.statefarm.codingcompetition.simpledatatool.model.Agent;
public class Application {
public static void main(String[] args) {
SimpleDataTool sdt = new SimpleDataTool();
-
+ for (Agent agent: sdt.getAgents()) {
+ System.out.println(agent.getFirst_name());
+ }
System.out.println("working");
}
}
diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java
index 046dd56..13519ac 100644
--- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java
+++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java
@@ -1,7 +1,13 @@
package com.statefarm.codingcompetition.simpledatatool.controller;
+import java.text.CollationElementIterator;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
import com.statefarm.codingcompetition.simpledatatool.io.JsonHelper;
import com.statefarm.codingcompetition.simpledatatool.model.Agent;
@@ -9,6 +15,8 @@
import com.statefarm.codingcompetition.simpledatatool.model.ClaimHandler;
import com.statefarm.codingcompetition.simpledatatool.model.Disaster;
+import static java.util.stream.Collectors.toList;
+
public class SimpleDataTool {
private static final String JSON_FILENAME_AGENTS = "sfcc_2023_agents.json";
@@ -58,7 +66,7 @@ public List getDisasters() {
* @return number of closed claims
*/
public int getNumClosedClaims() {
- return 0;
+ return (int) this.claims.stream().filter(claim -> claim.getStatus().equals("Closed")).count();
}
/**
@@ -68,7 +76,7 @@ public int getNumClosedClaims() {
* @return number of claims assigned to claim handler
*/
public int getNumClaimsForClaimHandlerId(int id) {
- return 0;
+ return (int) this.claims.stream().filter(claim -> claim.getClaim_handler_assigned_id() == id ).count();
}
/**
@@ -79,7 +87,8 @@ public int getNumClaimsForClaimHandlerId(int id) {
* @return number of disasters for state
*/
public int getNumDisastersForState(String stateName) {
- return -1;
+
+ return (int) this.disasters.stream().filter(disaster -> disaster.getState().equals(stateName)).count();
}
// endregion
@@ -93,8 +102,11 @@ public int getNumDisastersForState(String stateName) {
* @return estimate cost of disaster, rounded to the nearest hundredths place
* returns null if no claims are found
*/
- public Float getTotalClaimCostForDisaster(int id) {
- return -0.01f;
+ public Double getTotalClaimCostForDisaster(int id) {
+ if (this.claims.stream().anyMatch(claim -> claim.getDisaster_id() == id)) {
+ return this.claims.stream().filter(claim -> claim.getDisaster_id() == id).mapToDouble(Claim::getEstimate_cost).sum();
+ }
+ return null;
}
/**
@@ -105,7 +117,10 @@ public Float getTotalClaimCostForDisaster(int id) {
* or null if no claims are found
*/
public Float getAverageClaimCostforClaimHandler(int id) {
- return -0.01f;
+ if (this.claims.stream().anyMatch(claim -> claim.getClaim_handler_assigned_id() == id)) {
+ return (float) this.claims.stream().filter(claim -> claim.getClaim_handler_assigned_id() == id).mapToDouble(Claim::getEstimate_cost).average().orElse(0.0);
+ }
+ return null;
}
/**
@@ -121,7 +136,15 @@ public Float getAverageClaimCostforClaimHandler(int id) {
* @return single name of state
*/
public String getStateWithTheMostDisasters() {
- return null;
+ Map stateAndDisasterCount = this.disasters.stream()
+ .collect(Collectors.groupingBy(disaster -> disaster.getState(), Collectors.counting()));
+
+ List orderedStates = stateAndDisasterCount.entrySet().stream()
+ .sorted(Map.Entry.comparingByValue().reversed().thenComparing(Map.Entry.comparingByKey()))
+ .map(Map.Entry::getKey)
+ .collect(toList());
+
+ return orderedStates.get(0);
}
/**
@@ -137,7 +160,15 @@ public String getStateWithTheMostDisasters() {
* @return single name of state
*/
public String getStateWithTheLeastDisasters() {
- return null;
+ Map stateAndDisasterCount = this.disasters.stream()
+ .collect(Collectors.groupingBy(disaster -> disaster.getState(), Collectors.counting()));
+
+ List orderedStates = stateAndDisasterCount.entrySet().stream()
+ .sorted(Map.Entry.comparingByValue().thenComparing(Map.Entry.comparingByKey()))
+ .map(Map.Entry::getKey)
+ .collect(toList());
+
+ return orderedStates.get(0);
}
/**
@@ -149,7 +180,19 @@ public String getStateWithTheLeastDisasters() {
* or empty string if state doesn't exist
*/
public String getMostSpokenAgentLanguageByState(String string) {
- return null;
+ Map languageCount = this.agents.stream()
+ .filter(agent -> agent.getState().equals(string))
+ .collect(Collectors.groupingBy(agent -> agent.getSecondary_language(), Collectors.counting()));
+
+ List orderedLanguages = languageCount.entrySet().stream()
+ .sorted(Map.Entry.comparingByValue().reversed().thenComparing(Map.Entry.comparingByKey()))
+ .map(Map.Entry::getKey)
+ .collect(toList());
+
+ if (languageCount.size() == 0 || orderedLanguages.get(0) == "null")
+ return "";
+
+ return orderedLanguages.get(0);
}
/**
@@ -166,7 +209,17 @@ public String getMostSpokenAgentLanguageByState(String string) {
* null if agent does not exist, or agent has no claims (open or not)
*/
public Integer getNumOfOpenClaimsForAgentAndSeverity(int agentId, int minSeverityRating) {
- return -2;
+ if (minSeverityRating < 1 || minSeverityRating > 10) {
+ return -1;
+ } else if(this.agents.stream().noneMatch(agent -> agent.getId() == agentId) ||
+ this.claims.stream().noneMatch(claim -> claim.getAgent_assigned_id() == agentId)) {
+ return null;
+ } else {
+ return (int) this.claims.stream().filter(claim -> claim.getAgent_assigned_id() == agentId
+ && !claim.getStatus().equals("Closed") &&
+ claim.getSeverity_rating() >= minSeverityRating).count();
+ }
+
}
// endregion
@@ -179,7 +232,9 @@ public Integer getNumOfOpenClaimsForAgentAndSeverity(int agentId, int minSeverit
* @return number of disasters where the declared date is after the end date
*/
public int getNumDisastersDeclaredAfterEndDate() {
- return -1;
+ return (int) this.disasters.stream()
+ .filter(disaster -> disaster.getDeclared_date().compareTo(disaster.getEnd_date()) > 0)
+ .count();
}
/**
@@ -194,7 +249,16 @@ public int getNumDisastersDeclaredAfterEndDate() {
* to the agent
*/
public Map buildMapOfAgentsToTotalClaimCost() {
- return null;
+
+ Map agents_WithClaims_To_ClaimCost = this.claims.stream()
+ .collect(Collectors.groupingBy(claim -> claim.getAgent_assigned_id(), Collectors.summingDouble(Claim::getEstimate_cost)));
+
+ Map agents_To_Total_ClaimCost = new HashMap<>();
+
+ for (Agent agent: this.agents) {
+ agents_To_Total_ClaimCost.put(agent.getId(), (float) agents_WithClaims_To_ClaimCost.getOrDefault(agent.getId(), Double.valueOf(0)).doubleValue());
+ }
+ return agents_To_Total_ClaimCost;
}
/**
@@ -211,7 +275,16 @@ public Map buildMapOfAgentsToTotalClaimCost() {
* null if disaster does not exist
*/
public float calculateDisasterClaimDensity(int id) {
- return -0.01f;
+ if (this.disasters.stream().noneMatch(disaster -> disaster.getId() == id)) return -1;
+
+ List disasterRecord = this.disasters.stream().filter(disaster -> disaster.getId() == id).collect(Collectors.toList());
+
+ double area = Math.PI * Math.pow(disasterRecord.get(0).getRadius_miles(), 2);
+
+ double numOfClaims = this.claims.stream().filter(claim -> claim.getDisaster_id() == id).count();
+
+ return (float) ((float) numOfClaims/area);
+
}
// endregion
@@ -220,16 +293,51 @@ public float calculateDisasterClaimDensity(int id) {
/**
* Gets the top three months with the highest total claim cost
- *
+ *
* Hint:
* - Month should be full name like 01 is January and 12 is December
* - Year should be full four-digit year
* - List should be in descending order
- *
+ *
* @return three strings of month and year, descending order of highest claims
*/
public String[] getTopThreeMonthsWithHighestNumOfClaimsDesc() {
- return new String[1];
+
+ Map id_To_monthYear = new HashMap<>();
+
+ for (Disaster disaster : this.disasters) {
+ id_To_monthYear.put(disaster.getId(), getMonthAndYear(disaster.getDeclared_date()));
+ }
+
+ Map monthYear_To_TotalCost = new HashMap<>();
+
+ for (Claim claim: this.claims) {
+ String key = id_To_monthYear.get(claim.getDisaster_id());
+
+ if (monthYear_To_TotalCost.containsKey(key)) {
+ monthYear_To_TotalCost.put(key, monthYear_To_TotalCost.get(key) + claim.getEstimate_cost());
+ } else {
+ monthYear_To_TotalCost.put(key, claim.getEstimate_cost());
+ }
+ }
+
+ List monthYear_Desc_Order = monthYear_To_TotalCost.entrySet().stream()
+ .sorted(Map.Entry.comparingByValue().reversed())
+ .map(Map.Entry::getKey)
+ .collect(toList());
+
+
+ return monthYear_Desc_Order.subList(0, 3).toArray(new String[0]);
+ }
+
+ static String getMonthAndYear(LocalDate date) {
+ return convertToSupperCase(String.valueOf(date.getMonth())) + " " + date.getYear();
+ }
+
+ static String convertToSupperCase(String input) {
+ String firstLetter = input.substring(0, 1).toUpperCase();
+ String restOfWord = input.substring(1).toLowerCase();
+ return firstLetter + restOfWord;
}
// endregion
diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/model/Claim.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/model/Claim.java
index db223d9..4508406 100644
--- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/model/Claim.java
+++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/model/Claim.java
@@ -7,7 +7,7 @@ public class Claim {
private static final Gson GSON = new Gson();
private int id, disaster_id, severity_rating, agent_assigned_id, claim_handler_assigned_id;
- private float estimate_cost;
+ private double estimate_cost;
private boolean total_loss, loss_of_life;
private String status, type;
@@ -51,7 +51,7 @@ public void setClaim_handler_assigned_id(int claim_handler_assigned_id) {
this.claim_handler_assigned_id = claim_handler_assigned_id;
}
- public float getEstimate_cost() {
+ public double getEstimate_cost() {
return this.estimate_cost;
}
diff --git a/java/src/test/java/com/statefarm/codingcompetition/simpledatatool/TestSet3.java b/java/src/test/java/com/statefarm/codingcompetition/simpledatatool/TestSet3.java
index 8dbf87b..74671f5 100644
--- a/java/src/test/java/com/statefarm/codingcompetition/simpledatatool/TestSet3.java
+++ b/java/src/test/java/com/statefarm/codingcompetition/simpledatatool/TestSet3.java
@@ -57,7 +57,8 @@ public void test10_buildMapOfAgentsToTotalClaimCost() {
public void test11_calculateDisasterClaimDensity() {
assertEquals(0.00172f, controller.calculateDisasterClaimDensity(15), 0.00001);
assertEquals(0.00029f, controller.calculateDisasterClaimDensity(68), 0.00001);
- assertEquals(null, controller.calculateDisasterClaimDensity(101));
+ //Changed value below to -1 since the test breaks as function only returns float values
+ assertEquals(-1f, controller.calculateDisasterClaimDensity(101), 0.00001);
assertEquals(0.01624f, controller.calculateDisasterClaimDensity(64), 0.00001);
}
}