From 8b5fc0fa1493909c40b5ff8b78eee5cc038496b8 Mon Sep 17 00:00:00 2001 From: E <37807391+MrSeppukun@users.noreply.github.com> Date: Sun, 11 Oct 2020 00:54:07 -0400 Subject: [PATCH 1/8] Update CodingCompCsvUtil.java --- .../CodingCompCsvUtil.java | 220 +++++++++++++++++- 1 file changed, 209 insertions(+), 11 deletions(-) diff --git a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java index 58267da..e10cc5b 100644 --- a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java +++ b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java @@ -1,11 +1,11 @@ package sf.codingcompetition2020; +import java.io.File; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.Reader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.lang.reflect.Array; +import java.util.*; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -16,10 +16,7 @@ import com.fasterxml.jackson.dataformat.csv.CsvMapper; import com.fasterxml.jackson.dataformat.csv.CsvSchema; -import sf.codingcompetition2020.structures.Agent; -import sf.codingcompetition2020.structures.Claim; -import sf.codingcompetition2020.structures.Customer; -import sf.codingcompetition2020.structures.Vendor; +import sf.codingcompetition2020.structures.*; public class CodingCompCsvUtil { @@ -30,10 +27,78 @@ public class CodingCompCsvUtil { * @return -- List of entries being returned. */ public List readCsvFile(String filePath, Class classType) { + try { + Scanner scan = new Scanner(new File(filePath)); + List objectList = new ArrayList(); + scan.nextLine(); + + while (scan.hasNextLine()) { + String line = scan.nextLine(); + LinkedList lineData = new LinkedList(Arrays.asList(line.split(","))); + if (Agent.class.equals(classType)) { + Agent agent = new Agent(Integer.parseInt(lineData.get(0)), lineData.get(1), lineData.get(2), lineData.get(3), lineData.get(4)); + + objectList.add((T) agent); + } else if (classType.equals(Claim.class)) { + Claim claim = new Claim(Integer.parseInt(lineData.get(0)), Integer.parseInt(lineData.get(1)), Boolean.parseBoolean(lineData.get(2)), Integer.parseInt(lineData.get(3))); + + objectList.add((T) claim); + } else if (classType.equals(Vendor.class)) { + Vendor vendor = new Vendor(Integer.parseInt(lineData.get(0)), lineData.get(1), Integer.parseInt(lineData.get(2)), Boolean.parseBoolean(lineData.get(3))); + + objectList.add((T) vendor); + } else if (classType.equals(Customer.class)) { + + List dependentList = new ArrayList(); + + if (!lineData.get(8).isBlank()) { + String tempString =""; + + while (lineData.get(8).contains("\"")) { + + tempString += lineData.get(8); + tempString += ","; + lineData.remove(8); + } + + LinkedList dependentData = new LinkedList(Arrays.asList(tempString.split("\"\""))); + + + List names = new ArrayList(); + for (int i = 3; i < dependentData.size(); i += 4) { + names.add(dependentData.get(i)); + } + + + for (int i = 0; i < names.size(); i += 2) { + Dependent dependent = new Dependent(names.get(i), names.get(i + 1)); + dependentList.add(dependent); + } + Customer customer = new Customer(Integer.parseInt(lineData.get(0)), lineData.get(1), lineData.get(2), Integer.parseInt(lineData.get(3)), lineData.get(4), Integer.parseInt(lineData.get(5)), Short.parseShort(lineData.get(6)), lineData.get(7), dependentList, Boolean.parseBoolean(lineData.get(8)), Boolean.parseBoolean(lineData.get(9)), Boolean.parseBoolean(lineData.get(10)), lineData.get(11), Short.parseShort(lineData.get(12)), Integer.parseInt(lineData.get(13))); + objectList.add((T) customer); + } + + else { + List dependentList2 = new ArrayList(); + Customer customer = new Customer(Integer.parseInt(lineData.get(0)), lineData.get(1), lineData.get(2), Integer.parseInt(lineData.get(3)), lineData.get(4), Integer.parseInt(lineData.get(5)), Short.parseShort(lineData.get(6)), lineData.get(7), dependentList2 , Boolean.parseBoolean(lineData.get(9)), Boolean.parseBoolean(lineData.get(10)), Boolean.parseBoolean(lineData.get(11)), lineData.get(12), Short.parseShort(lineData.get(13)), Integer.parseInt(lineData.get(14))); + objectList.add((T) customer); + } + + + + } + } + return objectList; + } + catch (FileNotFoundException e){ + e.printStackTrace(); + + } + return null; } - + /* #2 * getAgentCountInArea() -- Return the number of agents in a given area. * @param filePath -- Path to file being read in. @@ -41,7 +106,17 @@ public List readCsvFile(String filePath, Class classType) { * @return -- The number of agents in a given area */ public int getAgentCountInArea(String filePath,String area) { + List agentList = readCsvFile(filePath, Agent.class); + int sum = 0; + for (int i = 0; i < agentList.size(); i++) { + if (agentList.get(i).getArea().equals(area)) { + sum++; + } + } + + return sum; + //return csvFile; } @@ -53,7 +128,17 @@ public int getAgentCountInArea(String filePath,String area) { * @return -- The number of agents in a given area */ public List getAgentsInAreaThatSpeakLanguage(String filePath, String area, String language) { + List agentList = readCsvFile(filePath, Agent.class); + List agentMatchList = new ArrayList(); + for (int i = 0; i < agentList.size(); i++) { + if (agentList.get(i).getArea().equals(area)) { + if(agentList.get(i).getLanguage().equals(language)) { + agentMatchList.add(agentList.get(i)); + } + } + } + return agentMatchList; } @@ -66,7 +151,26 @@ public List getAgentsInAreaThatSpeakLanguage(String filePath, String area * @return -- The number of customers that use a certain agent in a given area. */ public short countCustomersFromAreaThatUseAgent(Map csvFilePaths, String customerArea, String agentFirstName, String agentLastName) { - + + List agentList= readCsvFile(csvFilePaths.get("agentList"), Agent.class); + List customerList = readCsvFile(csvFilePaths.get("customerList"), Customer.class); + short sum = 0; + + for (int i = 0; i < customerList.size(); i++) { + if (customerList.get(i).getArea().equals(customerArea)) { + int agentId = 0; + for (int j = 0; j < agentList.size(); j++) { + if (agentList.get(j).getFirstName().equals(agentFirstName) && agentList.get(j).getLastName().equals(agentLastName)) { + agentId = agentList.get(j).getAgentId(); + } + } + if (agentId == customerList.get(i).getAgentId()) { + sum++; + } + } + } + + return sum; } @@ -77,7 +181,39 @@ public short countCustomersFromAreaThatUseAgent(Map csvFilePaths, * @return -- List of customers retained for a given number of years, in ascending order of policy cost. */ public List getCustomersRetainedForYearsByPlcyCostAsc(String customerFilePath, short yearsOfService) { + List customerList = readCsvFile(customerFilePath, Customer.class); + List validCustomers = new ArrayList(); + + for (int i = 0; i < customerList.size(); i++) { + if (customerList.get(i).getYearsOfService() == yearsOfService) { + validCustomers.add(customerList.get(i)); + } + } + + int tempMin = Integer.parseInt(validCustomers.get(0).getTotalMonthlyPremium().substring(1)); + int tempMinIndex = 0; + List sortedCustomers = new ArrayList(); + int size = validCustomers.size(); + + for (int i = 0; i < size; i++) { + tempMin = Integer.MAX_VALUE; + for (int j = 0; j < validCustomers.size(); j++) { + + + if (Integer.parseInt(validCustomers.get(j).getTotalMonthlyPremium().substring(1)) < tempMin) { + + tempMin = Integer.parseInt(validCustomers.get(j).getTotalMonthlyPremium().substring(1)); + tempMinIndex = j; + + + } + } + + sortedCustomers.add(validCustomers.get(tempMinIndex)); + validCustomers.remove(tempMinIndex); + } + return sortedCustomers; } @@ -88,7 +224,16 @@ public List getCustomersRetainedForYearsByPlcyCostAsc(String customerF * @return -- List of customers who’ve made an inquiry for a policy but have not signed up. */ public List getLeadsForInsurance(String filePath) { + List customerList = readCsvFile(filePath, Customer.class); + List potentialCustomers = new ArrayList(); + for (int i = 0; i < customerList.size(); i++) { + if (!customerList.get(i).isAutoPolicy() && !customerList.get(i).isHomePolicy() && !customerList.get(i).isRentersPolicy()) { + potentialCustomers.add(customerList.get(i)); + } + } + + return potentialCustomers; } @@ -103,7 +248,25 @@ b. Whether that vendor is in scope of the insurance (if inScope == false, return * @return -- List of vendors within a given area, filtered by scope and vendor rating. */ public List getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope, int vendorRating) { + List vendorList = readCsvFile(filePath, Vendor.class); + List validList = new ArrayList(); + + + for (int i = 0; i < vendorList.size(); i++) { + if (vendorList.get(i).getVendorRating() >= vendorRating && vendorList.get(i).getArea().equals(area)) { + if (inScope) { + if (vendorList.get(i).isInScope()) { + validList.add(vendorList.get(i)); + } + } + else { + validList.add(vendorList.get(i)); + } + } + } + + return validList; } @@ -117,7 +280,21 @@ public List getVendorsWithGivenRatingThatAreInScope(String filePath, Str * @return -- List of customers filtered by age, number of vehicles insured and the number of dependents. */ public List getUndisclosedDrivers(String filePath, int vehiclesInsured, int dependents) { + List customerList = readCsvFile(filePath, Customer.class); + List filteredList = new ArrayList(); + + for (int i = 0; i < customerList.size(); i++) { + if (customerList.get(i).getAge() >= 40 && customerList.get(i).getAge() <= 50) { + if (customerList.get(i).getVehiclesInsured() > vehiclesInsured) { + if (customerList.get(i).getDependents().size() <= dependents) { + filteredList.add(customerList.get(i)); + } + } + } + } + + return filteredList; } @@ -130,7 +307,7 @@ public List getUndisclosedDrivers(String filePath, int vehiclesInsured * @return -- Agent ID of agent with the given rank. */ public int getAgentIdGivenRank(String filePath, int agentRank) { - + return 0; } @@ -141,7 +318,28 @@ public int getAgentIdGivenRank(String filePath, int agentRank) { * @return -- List of customers who’ve filed a claim within the last . */ public List getCustomersWithClaims(Map csvFilePaths, short monthsOpen) { + List claimList = readCsvFile(csvFilePaths.get("claimList"), Claim.class); + List customerList = readCsvFile(csvFilePaths.get("customerList"), Customer.class); + + List validCustomers = new ArrayList(); + int customerId = 0; + + for (int i = 0; i < claimList.size(); i++) { + //customerId = 0; + if (claimList.get(i).getMonthsOpen() <= monthsOpen) { + customerId = claimList.get(i).getCustomerId(); + + System.out.println(customerId); + for (int j = 0; j < customerList.size(); j++) { + if (customerId == customerList.get(j).getCustomerId()) { + validCustomers.add(customerList.get(j)); + } + } + } + } + + return validCustomers; } } From 21d300c2448ae450cc83895280b140e81f8f59a0 Mon Sep 17 00:00:00 2001 From: E <37807391+MrSeppukun@users.noreply.github.com> Date: Sun, 11 Oct 2020 00:54:38 -0400 Subject: [PATCH 2/8] Update Agent.java --- .../structures/Agent.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/sf/codingcompetition2020/structures/Agent.java b/src/main/java/sf/codingcompetition2020/structures/Agent.java index e2e6f93..d38a250 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Agent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Agent.java @@ -7,5 +7,33 @@ public class Agent { private String language; private String firstName; private String lastName; + + public Agent(int agentId, String area, String language, String firstName, String lastName) { + this.agentId = agentId; + this.area = area; + this.language = language; + this.firstName = firstName; + this.lastName = lastName; + } + + public int getAgentId() { + return agentId; + } + + public String getArea() { + return area; + } + + public String getLanguage() { + return language; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } } From 51cdfead9a9e86bf54a637abb1255597e50549b0 Mon Sep 17 00:00:00 2001 From: E <37807391+MrSeppukun@users.noreply.github.com> Date: Sun, 11 Oct 2020 00:55:08 -0400 Subject: [PATCH 3/8] Update Claim.java --- .../structures/Claim.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/sf/codingcompetition2020/structures/Claim.java b/src/main/java/sf/codingcompetition2020/structures/Claim.java index 581140a..3244f02 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Claim.java +++ b/src/main/java/sf/codingcompetition2020/structures/Claim.java @@ -5,5 +5,29 @@ public class Claim { private int customerId; private boolean closed; private int monthsOpen; - + + public Claim(int claimId, int customerId, boolean closed, int monthsOpen) { + this.claimId = claimId; + this.customerId = customerId; + this.closed = closed; + this.monthsOpen = monthsOpen; + } + + public int getClaimId() { + return claimId; + } + + public int getCustomerId() { + return customerId; + } + + public int getMonthsOpen() { + return monthsOpen; + } + + public boolean isClosed() { + return closed; + } + + } From 612f4b5f096f4cd07032de9eb2e894c159caf35a Mon Sep 17 00:00:00 2001 From: E <37807391+MrSeppukun@users.noreply.github.com> Date: Sun, 11 Oct 2020 00:55:31 -0400 Subject: [PATCH 4/8] Update Customer.java --- .../structures/Customer.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/main/java/sf/codingcompetition2020/structures/Customer.java b/src/main/java/sf/codingcompetition2020/structures/Customer.java index f151906..ae18fc8 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Customer.java +++ b/src/main/java/sf/codingcompetition2020/structures/Customer.java @@ -24,4 +24,82 @@ public class Customer { private short yearsOfService; private Integer vehiclesInsured; + public Customer(int customerId, String firstName, String lastName, int age, String area, int agentId, short agentRating, String primaryLanguage, List dependents, boolean homePolicy, boolean autoPolicy, boolean rentersPolicy, String totalMonthlyPremium, short yearsOfService, Integer vehiclesInsured) { + this.customerId = customerId; + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + this.area = area; + this.agentId = agentId; + this.agentRating = agentRating; + this.primaryLanguage = primaryLanguage; + this.dependents = dependents; + this.homePolicy = homePolicy; + this.autoPolicy = autoPolicy; + this.rentersPolicy = rentersPolicy; + this.totalMonthlyPremium = totalMonthlyPremium; + this.yearsOfService = yearsOfService; + this.vehiclesInsured = vehiclesInsured; + } + + public int getCustomerId() { + return customerId; + } + + public String getFirstName() { + return firstName; + } + + public boolean isAutoPolicy() { + return autoPolicy; + } + + public boolean isHomePolicy() { + return homePolicy; + } + + public boolean isRentersPolicy() { + return rentersPolicy; + } + + public int getAge() { + return age; + } + + public int getAgentId() { + return agentId; + } + + public Integer getVehiclesInsured() { + return vehiclesInsured; + } + + public List getDependents() { + return dependents; + } + + public short getAgentRating() { + return agentRating; + } + + public short getYearsOfService() { + return yearsOfService; + } + + public String getArea() { + return area; + } + + public String getLastName() { + return lastName; + } + + public String getPrimaryLanguage() { + return primaryLanguage; + } + + public String getTotalMonthlyPremium() { + return totalMonthlyPremium; + } + } From b574ce6bd63a33f308e4e3148bece99bfe3864a8 Mon Sep 17 00:00:00 2001 From: E <37807391+MrSeppukun@users.noreply.github.com> Date: Sun, 11 Oct 2020 00:55:58 -0400 Subject: [PATCH 5/8] Update Dependent.java --- .../structures/Dependent.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/sf/codingcompetition2020/structures/Dependent.java b/src/main/java/sf/codingcompetition2020/structures/Dependent.java index d4deb1a..927ed74 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Dependent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Dependent.java @@ -4,4 +4,18 @@ public class Dependent { private String firstName; private String lastName; + public Dependent(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getLastName() { + return lastName; + } + + public String getFirstName() { + return firstName; + } + + } From da358ebf3ccc4213ddd0bf5f13e92f66f22f575f Mon Sep 17 00:00:00 2001 From: E <37807391+MrSeppukun@users.noreply.github.com> Date: Sun, 11 Oct 2020 00:56:24 -0400 Subject: [PATCH 6/8] Update Vendor.java --- .../structures/Vendor.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/sf/codingcompetition2020/structures/Vendor.java b/src/main/java/sf/codingcompetition2020/structures/Vendor.java index 6b6fb76..f90c39c 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Vendor.java +++ b/src/main/java/sf/codingcompetition2020/structures/Vendor.java @@ -5,5 +5,27 @@ public class Vendor { private String area; private int vendorRating; private boolean inScope; - + + public Vendor(int vendorId, String area, int vendorRating, boolean inScope) { + this.vendorId = vendorId; + this.area = area; + this.vendorRating = vendorRating; + this.inScope = inScope; + } + + public String getArea() { + return area; + } + + public boolean isInScope() { + return inScope; + } + + public int getVendorId() { + return vendorId; + } + + public int getVendorRating() { + return vendorRating; + } } From 88ca771019bb2ca08ce28c4d33f2608ffd8623d1 Mon Sep 17 00:00:00 2001 From: E <37807391+MrSeppukun@users.noreply.github.com> Date: Sun, 11 Oct 2020 00:56:43 -0400 Subject: [PATCH 7/8] Update feedback.txt --- feedback.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/feedback.txt b/feedback.txt index b931d50..5e69eb7 100644 --- a/feedback.txt +++ b/feedback.txt @@ -1,9 +1,7 @@ -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 Eyerly & Micah Lingle +How many JUnits were you able to get to pass? 8 / 10 Document and describe any enhancements included to help the judges properly grade your submission. - Step 1: - Step 2: - Feedback for the coding competition? Things you would like to see in future events? +Make instructions for what Junits want a little clearer perhaps. From 966df281d85b55c93e4523c6cda3210e151b4f1d Mon Sep 17 00:00:00 2001 From: E <37807391+MrSeppukun@users.noreply.github.com> Date: Sun, 11 Oct 2020 00:57:04 -0400 Subject: [PATCH 8/8] Update pom.xml --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index 21d55bf..e1609e3 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,8 @@ Coding Competition + 14 + 14