diff --git a/feedback.txt b/feedback.txt index b931d50..5e6b73b 100644 --- a/feedback.txt +++ b/feedback.txt @@ -1,9 +1,10 @@ -Your team (name of each individual participating): +Your team: Chris Moore, Conley Price How many JUnits were you able to get to pass? + 4 Document and describe any enhancements included to help the judges properly grade your submission. - Step 1: - Step 2: + None Feedback for the coding competition? Things you would like to see in future events? + None diff --git a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java index 58267da..d2a3aac 100644 --- a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java +++ b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java @@ -1,11 +1,16 @@ 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.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Scanner; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -22,126 +27,288 @@ import sf.codingcompetition2020.structures.Vendor; public class CodingCompCsvUtil { - - /* #1 - * readCsvFile() -- Read in a CSV File and return a list of entries in that file. + + /* + * #1 readCsvFile() -- Read in a CSV File and return a list of entries in that + * file. + * * @param filePath -- Path to file being read in. + * * @param classType -- Class of entries being read in. + * * @return -- List of entries being returned. */ public List readCsvFile(String filePath, Class classType) { + List temp = new ArrayList(); + + try { + Scanner scan = new Scanner(new File(filePath)); + String line = ""; + + while (scan.hasNextLine()) { + line = scan.nextLine(); + String[] lineList = line.split(","); + T c = classType.cast(new Agent(lineList)); + if (classType == Agent.class) { + temp.add(classType.cast(new Agent(lineList))); + } else if (classType == Claim.class) { + temp.add(classType.cast(new Claim(lineList))); + } else if (classType == Vendor.class) { + temp.add(classType.cast(new Vendor(lineList))); + } else if (classType == Customer.class) { + temp.add(classType.cast(new Customer(createCustomerList(lineList)))); + } + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return null; + } + private String[] createCustomerList(String[] list) { + String[] out = new String[15]; + for (int i = 0; i < 8; i++) { + out[i] = list[i]; + } + StringBuffer sb = new StringBuffer(); + for (int i = 8; i < list.length - 6; i++) { + sb.append(list[i]); + } + out[8] = sb.toString(); + for (int i = 0; i < 6; i++) { + out[14 - i] = list[list.length - 1 - i]; + } + return out; } - - /* #2 - * getAgentCountInArea() -- Return the number of agents in a given area. + /* + * #2 getAgentCountInArea() -- Return the number of agents in a given area. + * * @param filePath -- Path to file being read in. + * * @param area -- The area from which the agents should be counted. + * * @return -- The number of agents in a given area */ - public int getAgentCountInArea(String filePath,String area) { + public int getAgentCountInArea(String filePath, String area) { + + try { + Scanner scan = new Scanner(new File(filePath)); + scan.nextLine(); + int count = 0; + while (scan.hasNextLine()) { + String areaTemp = scan.nextLine().split(",")[1]; + if (areaTemp.equals(area)) { + count++; + } + } + return count; + } catch (FileNotFoundException e) { + return (Integer) null; + } } - - /* #3 - * getAgentsInAreaThatSpeakLanguage() -- Return a list of agents from a given area, that speak a certain language. + /* + * #3 getAgentsInAreaThatSpeakLanguage() -- Return a list of agents from a given + * area, that speak a certain language. + * * @param filePath -- Path to file being read in. + * * @param area -- The area from which the agents should be counted. + * * @param language -- The language spoken by the agent(s). + * * @return -- The number of agents in a given area */ public List getAgentsInAreaThatSpeakLanguage(String filePath, String area, String language) { + List result = new ArrayList(); + + try { + Scanner scan = new Scanner(new File(filePath)); + scan.nextLine(); + int count = 0; + while (scan.hasNextLine()) { + String[] areaTemp = scan.nextLine().split(","); + if (areaTemp[1].equals(area) && areaTemp[2].equals(language)) { + Agent temp = new Agent(areaTemp); + result.add(temp); + } + } + return result; + } catch (FileNotFoundException e) { + return null; + } } - - - /* #4 - * countCustomersFromAreaThatUseAgent() -- Return the number of individuals from an area that use a certain agent. + + /* + * #4 countCustomersFromAreaThatUseAgent() -- Return the number of individuals + * from an area that use a certain agent. + * * @param filePath -- Path to file being read in. + * * @param customerArea -- The area from which the customers should be counted. + * * @param agentFirstName -- First name of agent. + * * @param agentLastName -- Last name of agent. + * * @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) { - + public short countCustomersFromAreaThatUseAgent(Map csvFilePaths, String customerArea, + String agentFirstName, String agentLastName) { + return -1; } - - /* #5 - * getCustomersRetainedForYearsByPlcyCostAsc() -- Return a list of customers retained for a given number of years, in ascending order of their policy cost. + /* + * #5 getCustomersRetainedForYearsByPlcyCostAsc() -- Return a list of customers + * retained for a given number of years, in ascending order of their policy + * cost. + * * @param filePath -- Path to file being read in. + * * @param yearsOfServeice -- Number of years the person has been a customer. - * @return -- List of customers retained for a given number of years, in ascending order of policy cost. + * + * @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 result = new ArrayList(); + + try { + Scanner scan = new Scanner(new File(customerFilePath)); + scan.nextLine(); + while (scan.hasNextLine()) { + String[] list = scan.nextLine().split(","); + if (list[list.length - 2].equals(yearsOfService + "")) { + for (String string : createCustomerList(list)) { + System.out.println(string); + } + System.out.println("\n\n"); + Customer temp = new Customer(createCustomerList(list)); + result.add(temp); + } + } + Collections.sort(result, new customerCostCompare()); + return result; + } catch (FileNotFoundException e) { + return null; + } } - - /* #6 - * getLeadsForInsurance() -- Return a list of individuals who’ve made an inquiry for a policy but have not signed up. - * *HINT* -- Look for customers that currently have no policies with the insurance company. + /* + * #6 getLeadsForInsurance() -- Return a list of individuals who’ve made an + * inquiry for a policy but have not signed up. *HINT* -- Look for customers + * that currently have no policies with the insurance company. + * * @param filePath -- Path to file being read in. - * @return -- List of customers who’ve made an inquiry for a policy but have not signed up. + * + * @return -- List of customers who’ve made an inquiry for a policy but have + * not signed up. */ public List getLeadsForInsurance(String filePath) { + List result = new ArrayList(); - } + try { + Scanner scan = new Scanner(new File(filePath)); + scan.nextLine(); + while (scan.hasNextLine()) { + String[] temp = scan.nextLine().split(","); + if (temp.length > 4 && temp[temp.length - 4].equals("false") && temp[temp.length - 5].equals("false") + && temp[temp.length - 6].equals("false")) { + Customer c = new Customer(createCustomerList(temp)); + result.add(c); + } + } + } catch (FileNotFoundException e) { + return null; + } + return result; + } - /* #7 - * getVendorsWithGivenRatingThatAreInScope() -- Return a list of vendors within an area and include options to narrow it down by: - a. Vendor rating - b. Whether that vendor is in scope of the insurance (if inScope == false, return all vendors in OR out of scope, if inScope == true, return ONLY vendors in scope) + /* + * #7 getVendorsWithGivenRatingThatAreInScope() -- Return a list of vendors + * within an area and include options to narrow it down by: a. Vendor rating b. + * Whether that vendor is in scope of the insurance (if inScope == false, return + * all vendors in OR out of scope, if inScope == true, return ONLY vendors in + * scope) + * * @param filePath -- Path to file being read in. + * * @param area -- Area of the vendor. + * * @param inScope -- Whether or not the vendor is in scope of the insurance. + * * @param vendorRating -- The rating of the vendor. - * @return -- List of vendors within a given area, filtered by scope and vendor rating. + * + * @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) { + public List getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope, + int vendorRating) { + return null; } - - /* #8 - * getUndisclosedDrivers() -- Return a list of customers between the age of 40 and 50 years (inclusive), who have: - a. More than X cars - b. less than or equal to X number of dependents. + /* + * #8 getUndisclosedDrivers() -- Return a list of customers between the age of + * 40 and 50 years (inclusive), who have: a. More than X cars b. less than or + * equal to X number of dependents. + * * @param filePath -- Path to file being read in. + * * @param vehiclesInsured -- The number of vehicles insured. + * * @param dependents -- The number of dependents on the insurance policy. - * @return -- List of customers filtered by age, number of vehicles insured and the number of dependents. + * + * @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) { - } - + return null; + } - /* #9 - * getAgentIdGivenRank() -- Return the agent with the given rank based on average customer satisfaction rating. - * *HINT* -- Rating is calculated by taking all the agent rating by customers (1-5 scale) and dividing by the total number - * of reviews for the agent. + /* + * #9 getAgentIdGivenRank() -- Return the agent with the given rank based on + * average customer satisfaction rating. *HINT* -- Rating is calculated by + * taking all the agent rating by customers (1-5 scale) and dividing by the + * total number of reviews for the agent. + * * @param filePath -- Path to file being read in. + * * @param agentRank -- The rank of the agent being requested. + * * @return -- Agent ID of agent with the given rank. */ public int getAgentIdGivenRank(String filePath, int agentRank) { - - } + return -1; + } - - /* #10 - * getCustomersWithClaims() -- Return a list of customers who’ve filed a claim within the last (inclusive). + /* + * #10 getCustomersWithClaims() -- Return a list of customers who’ve filed a + * claim within the last (inclusive). + * * @param filePath -- Path to file being read in. + * * @param monthsOpen -- Number of months a policy has been open. - * @return -- List of customers who’ve filed a claim within the last . + * + * @return -- List of customers who’ve filed a claim within the last + * . */ - public List getCustomersWithClaims(Map csvFilePaths, short monthsOpen) { + public List getCustomersWithClaims(Map csvFilePaths, short monthsOpen) { + + return null; + } - } + private class customerCostCompare implements Comparator { + public int compare(Customer o1, Customer o2) { + return o1.getTotalMonthlyPremium().compareTo(o2.getTotalMonthlyPremium()); + } + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Agent.java b/src/main/java/sf/codingcompetition2020/structures/Agent.java index e2e6f93..ffb19b0 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Agent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Agent.java @@ -8,4 +8,61 @@ public class Agent { private String firstName; private String lastName; + public Agent(String[] items){ + try { + this.agentId = Integer.parseInt(items[0]); + } catch (Exception e) { + this.agentId = -1; + } + this.area = items[1]; + this.language = items[2]; + this.firstName = items[3]; + this.lastName = items[4]; + } + + public int getAgentId() { + return agentId; + } + + public void setAgentId(int agentId) { + this.agentId = agentId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public void setArea(String area) { + this.area = area; + } + + public void setLanguage(String language) { + this.language = language; + } + + //get agent area + public String getArea() { + return area; + } + + //get language + public String getLanguage() { + return language; + } + + + + } diff --git a/src/main/java/sf/codingcompetition2020/structures/Claim.java b/src/main/java/sf/codingcompetition2020/structures/Claim.java index 581140a..374316e 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Claim.java +++ b/src/main/java/sf/codingcompetition2020/structures/Claim.java @@ -6,4 +6,28 @@ public class Claim { private boolean closed; private int monthsOpen; + + public Claim(String[] items) { + this.claimId = Integer.parseInt(items[0]); + this.customerId = Integer.parseInt(items[1]); + this.closed = closed; + this.monthsOpen = Integer.parseInt(items[3]); + } + + + + + public int getMonthsOpen() { + return monthsOpen; + } + + + + + public int getClaimId() { + // TODO Auto-generated method stub + return claimId; + } + + } diff --git a/src/main/java/sf/codingcompetition2020/structures/Customer.java b/src/main/java/sf/codingcompetition2020/structures/Customer.java index f151906..36aa555 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Customer.java +++ b/src/main/java/sf/codingcompetition2020/structures/Customer.java @@ -1,7 +1,10 @@ package sf.codingcompetition2020.structures; +import java.io.File; +import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; +import java.util.Scanner; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; @@ -24,4 +27,113 @@ public class Customer { private short yearsOfService; private Integer vehiclesInsured; + public Customer(String[] items) { + this.customerId = Integer.parseInt(items[0]); + this.firstName = items[1]; + this.lastName = items[2]; + this.age = Integer.parseInt(items[3]); + this.area = items[4]; + this.agentId = Integer.parseInt(items[5]); + this.agentRating = (short) Integer.parseInt(items[6]); + this.primaryLanguage = items[7]; + this.dependents = parseDependent(items[8]); + this.homePolicy = bolParse(items[9]); + this.autoPolicy = bolParse(items[10]); + this.rentersPolicy = bolParse(items[11]); + this.totalMonthlyPremium = items[12]; + this.yearsOfService = (short) Integer.parseInt(items[13]); + this.vehiclesInsured = Integer.parseInt(items[14]); + } + + private boolean bolParse(String n) { + if (n.equalsIgnoreCase("true")) { + return true; + } else { + return false; + } + } + + private List parseDependent(String list) { + if (list.length() == 0) { + return null; + } + + List temp = new ArrayList(); + + int firstPos = list.indexOf("firstName"); + while (firstPos != -1) { + String beginWithFirst = list.substring(firstPos+12); + String first = beginWithFirst.substring(0,beginWithFirst.indexOf("\"")); + + String beginWithLast = beginWithFirst.substring(first.length()+14); + String last = beginWithLast.substring(0,beginWithLast.indexOf("\"")); + + temp.add(new Dependent(first, last)); + + list = beginWithLast; + firstPos = list.indexOf("firstName"); + } + return temp; + } + + public int getCustomerId() { + return customerId; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public int getAge() { + return age; + } + + public String getArea() { + return area; + } + + public int getAgentId() { + return agentId; + } + + public short getAgentRating() { + return agentRating; + } + + public String getPrimaryLanguage() { + return primaryLanguage; + } + + public List getDependents() { + return dependents; + } + + public boolean isHomePolicy() { + return homePolicy; + } + + public boolean isAutoPolicy() { + return autoPolicy; + } + + public boolean isRentersPolicy() { + return rentersPolicy; + } + + public String getTotalMonthlyPremium() { + return totalMonthlyPremium; + } + + public short getYearsOfService() { + return yearsOfService; + } + + public Integer getVehiclesInsured() { + return vehiclesInsured; + } + } diff --git a/src/main/java/sf/codingcompetition2020/structures/Dependent.java b/src/main/java/sf/codingcompetition2020/structures/Dependent.java index d4deb1a..129554f 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Dependent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Dependent.java @@ -4,4 +4,9 @@ public class Dependent { private String firstName; private String lastName; + + public Dependent(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Vendor.java b/src/main/java/sf/codingcompetition2020/structures/Vendor.java index 6b6fb76..108a6de 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Vendor.java +++ b/src/main/java/sf/codingcompetition2020/structures/Vendor.java @@ -6,4 +6,36 @@ public class Vendor { private int vendorRating; private boolean inScope; + public Vendor(String [] items) { + this.vendorId = Integer.parseInt(items[0]); + this.area = items[1]; + this.vendorRating = Integer.parseInt(items[2]); + this.inScope = bolParse(items[3]); + } + + private boolean bolParse(String n) { + if (n.equals("TRUE")) { + return true; + } else { + return false; + } + } + + public int getVendorId() { + return vendorId; + } + + public String getArea() { + return area; + } + + public int getVendorRating() { + return vendorRating; + } + + public boolean isInScope() { + return inScope; + } + + } diff --git a/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java b/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java index c29959f..85bb197 100644 --- a/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java +++ b/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java @@ -56,7 +56,7 @@ public void getAgentsInAreaThatSpeakLanguage() { //#4 @Test public void countCustomersFromCitythatUseAgent() { - Map csvFilePaths = new HashMap<>(); + Map csvFilePaths = new HashMap(); csvFilePaths.put(agentList, agentFilePath); csvFilePaths.put(customerList, customerFilePath); @@ -111,7 +111,7 @@ public void getAgentIdGivenRank() { //#10 @Test public void getCountCustomersWithClaims() { - Map csvFilePaths = new HashMap<>(); + Map csvFilePaths = new HashMap(); csvFilePaths.put(customerList, customerFilePath); csvFilePaths.put(claimList, claimFilePath);