Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Final Submission #29

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions FEEDBACK.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# Feedback

1. Your team:

My team name is CodeGuy

2. Name of each individual participating:

Carl Ghess

3. How many unit tests were you able to pass?

7. 13 unit tests were run, 5 were failures (not completed) and one was an error

4. Document and describe any enhancements included to help the judges properly grade your submission.
- Example One
- Example Two
- Example Three

Due to time constraints, no enhancements were included

5. Any feedback for the coding competition? Things you would like to see in future events?

No. This is my first one, so I wasn't sure what to expect. I liked it

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.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@ public static void main(String[] args) {
SimpleDataTool sdt = new SimpleDataTool();

System.out.println("working");

// System.out.println(sdt.getNumClosedClaims());
// // System.out.println(sdt.getNumClaimsForClaimHandlerId(19));
// // System.out.println(sdt.getNumDisastersForState("Texas"));
// // System.out.println(sdt.getTotalClaimCostForDisaster(19));
// // System.out.println(sdt.getAverageClaimCostforClaimHandler(12));
// // System.out.println(sdt.getStateWithTheMostDisasters());
// System.out.println(sdt.getStateWithTheLeastDisasters());
System.out.println(sdt.getMostSpokenAgentLanguageByState("Texas"));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.statefarm.codingcompetition.simpledatatool.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import com.statefarm.codingcompetition.simpledatatool.io.JsonHelper;
import com.statefarm.codingcompetition.simpledatatool.model.Agent;
Expand Down Expand Up @@ -58,7 +61,20 @@ public List<Disaster> getDisasters() {
* @return number of closed claims
*/
public int getNumClosedClaims() {
return 0;
int closedClaims = 0;

List<Claim> claims = getClaims();

for (Claim claim : claims) {

String status = claim.getStatus();
if (status.equals("Closed"))
closedClaims++;

}

int result = closedClaims == 0 ? -1 : closedClaims;
return result;
}

/**
Expand All @@ -68,7 +84,20 @@ public int getNumClosedClaims() {
* @return number of claims assigned to claim handler
*/
public int getNumClaimsForClaimHandlerId(int id) {
return 0;
int claimsForClaimHandler = 0;

List<Claim> claims = getClaims();

for (Claim claim : claims) {

int claimHandlerID = claim.getClaim_handler_assigned_id();
if (claimHandlerID == id)
claimsForClaimHandler++;

}

int result = claimsForClaimHandler == 0 ? -1 : claimsForClaimHandler;
return result;
}

/**
Expand All @@ -79,7 +108,18 @@ public int getNumClaimsForClaimHandlerId(int id) {
* @return number of disasters for state
*/
public int getNumDisastersForState(String stateName) {
return -1;
int numDisasters = 0;

List<Disaster> disasters = getDisasters();

for (Disaster disaster : disasters) {

if (disaster.getState().equals(stateName))
numDisasters++;
}

int result = numDisasters == 0 ? -1 : numDisasters;
return result;
}

// endregion
Expand All @@ -94,7 +134,23 @@ public int getNumDisastersForState(String stateName) {
* returns null if no claims are found
*/
public Float getTotalClaimCostForDisaster(int id) {
return -0.01f;
float totalClaimCost = 0;

List<Claim> claims = getClaims();

for (Claim claim : claims) {

if (claim.getDisaster_id() != id)
continue;
totalClaimCost += claim.getEstimate_cost();

}

if (totalClaimCost == 0)
return null;

String result = String.format("%.2f", totalClaimCost);
return Float.parseFloat(result);
}

/**
Expand All @@ -105,7 +161,30 @@ public Float getTotalClaimCostForDisaster(int id) {
* or null if no claims are found
*/
public Float getAverageClaimCostforClaimHandler(int id) {
return -0.01f;

float avgClaimCost = 0;
float totalClaimCost = 0;

List<Claim> claims = getClaims();

int noOfClaims = 0;
for (Claim claim : claims) {

if (claim.getClaim_handler_assigned_id() != id)
continue;
noOfClaims++;

totalClaimCost += claim.getEstimate_cost();
}

if (noOfClaims == 0)
return null;

avgClaimCost = totalClaimCost / noOfClaims;

String result = String.format("%.2f", avgClaimCost);

return Float.parseFloat(result);
}

/**
Expand All @@ -121,7 +200,35 @@ public Float getAverageClaimCostforClaimHandler(int id) {
* @return single name of state
*/
public String getStateWithTheMostDisasters() {
return null;

SortedMap<String, Integer> stateMap = new TreeMap<String, Integer>();

List<Disaster> disasters = getDisasters();

for (Disaster disaster : disasters) {

String stateName = disaster.getState();

if (!stateMap.containsKey(stateName)) { // initialize if new element
stateMap.put(stateName, 1);
continue;
}

stateMap.put(stateName, stateMap.get(stateName) + 1); // Add one if existing element
}

String result = "";
int topDisasters = 0;
// loop through map and take greatest # of disasters in alphabetical order
for (Map.Entry<String, Integer> element : stateMap.entrySet()) {

if (element.getValue() < topDisasters || element.getValue() == topDisasters)
continue;
topDisasters = element.getValue();
result = element.getKey();
}

return result;
}

/**
Expand All @@ -137,7 +244,41 @@ public String getStateWithTheMostDisasters() {
* @return single name of state
*/
public String getStateWithTheLeastDisasters() {
return null;

SortedMap<String, Integer> stateMap = new TreeMap<String, Integer>();

List<Disaster> disasters = getDisasters();

for (Disaster disaster : disasters) {

String stateName = disaster.getState();

if (!stateMap.containsKey(stateName)) { // initialize if new element
stateMap.put(stateName, 1);
continue;
}

stateMap.put(stateName, stateMap.get(stateName) + 1); // Add one if existing element
}

String result = "";
int leastDisasters = 0;
// loop through map and take the least # of disasters in alphabetical order
for (Map.Entry<String, Integer> element : stateMap.entrySet()) {

if (leastDisasters == 0) { // initialize least disasters
leastDisasters = element.getValue();
continue;
}

if (element.getValue() > leastDisasters || element.getValue() == leastDisasters)
continue;

leastDisasters = element.getValue();
result = element.getKey();
}

return result;
}

/**
Expand All @@ -149,7 +290,41 @@ public String getStateWithTheLeastDisasters() {
* or empty string if state doesn't exist
*/
public String getMostSpokenAgentLanguageByState(String string) {
return null;

HashMap<String, Integer> languageMap = new HashMap<String, Integer>();

List<Agent> agents = getAgents();

//loop through and fill HashMap
for (Agent agent : agents) {

if(!string.equals(agent.getState())) continue;
String secondaryLan = agent.getSecondary_language();

if (!languageMap.containsKey(secondaryLan)) { // initialize if new element
languageMap.put(secondaryLan, 1);
continue;
}

languageMap.put(secondaryLan, languageMap.get(secondaryLan) + 1); // Add one if existing element
}

String result = "";
int mostSpoken = 0;
// loop through map and take the most spoken secondary language
for (Map.Entry<String, Integer> element : languageMap.entrySet()) {



if (element.getValue() < mostSpoken)
continue;

mostSpoken = element.getValue();
result = element.getKey();
}


return result;
}

/**
Expand Down