diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..1b799f3 --- /dev/null +++ b/.classpath @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..f150776 --- /dev/null +++ b/.project @@ -0,0 +1,34 @@ + + + coding-competition + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + 1602378236374 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..d4313d4 --- /dev/null +++ b/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ac8e750 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +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.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/feedback.txt b/feedback.txt index b931d50..4cc81a4 100644 --- a/feedback.txt +++ b/feedback.txt @@ -1,9 +1,10 @@ -Your team (name of each individual participating): -How many JUnits were you able to get to pass? +Your team (name of each individual participating): Evan Mitchell and Li Ying (Merissa) Tan +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. Add function getPossibleVendorsForClaim() + 2. Graph number of claims open for n months (run Gui.java) + 3. Graph agent count in area i (run Gui.java) + + Feedback for the coding competition? Things you would like to see in future events? diff --git a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java index 58267da..59a2929 100644 --- a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java +++ b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java @@ -1,11 +1,18 @@ package sf.codingcompetition2020; +import java.io.BufferedReader; import java.io.FileReader; +import java.io.IOException; import java.io.Reader; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -20,31 +27,79 @@ import sf.codingcompetition2020.structures.Claim; import sf.codingcompetition2020.structures.Customer; import sf.codingcompetition2020.structures.Vendor; +import sf.codingcompetition2020.structures.Dependent; public class CodingCompCsvUtil { - - /* #1 + + /* #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 result = new ArrayList(); + try { + BufferedReader csvReader = new BufferedReader(new FileReader(filePath)); + String row = csvReader.readLine(); + while ((row = csvReader.readLine()) != null) { + String[] data = row.split(",(?![^\\[]*\\])"); + if (classType == Agent.class) { + T agent = (T) new Agent(Integer.parseInt(data[0]), data[1], data[2], data[3], data[4]); + result.add(agent); + } else if (classType == Claim.class) { + T claim = (T) new Claim(Integer.parseInt(data[0]), Integer.parseInt(data[1]), Boolean.parseBoolean(data[2]), + Integer.parseInt(data[3])); + result.add(claim); + } else if (classType == Customer.class) { + List dependentsList = new ArrayList(); + if (data[8].length() > 0) { + String[] dependents = data[8].substring(1, data[8].length() - 1).split(",(?![^{]*})"); + for (String dependent : dependents) { + String[] name = dependent.substring(1, dependent.length() - 1).split(","); + String firstName = name[0].split("\"\"")[2]; + String lastName = name[1].split("\"\"")[2]; + dependentsList.add(new Dependent(firstName, lastName)); + } + } + T customer = (T) new Customer(Integer.parseInt(data[0]), data[1], data[2], Integer.parseInt(data[3]), data[4], + Integer.parseInt(data[5]), Short.parseShort(data[6]), data[7], dependentsList, + Boolean.parseBoolean(data[9]), Boolean.parseBoolean(data[10]), Boolean.parseBoolean(data[11]), data[12], + Short.parseShort(data[13]), Integer.parseInt(data[14])); + result.add(customer); + } else if (classType == Vendor.class) { + T vendor = (T) new Vendor(Integer.parseInt(data[0]), data[1], Integer.parseInt(data[2]), + Boolean.parseBoolean(data[3])); + result.add(vendor); + } else { + return null; + } + } + csvReader.close(); + } catch (IOException e) { + return null; + } + return result; } - /* #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) { + List agents = readCsvFile(filePath, Agent.class); + int result = 0; + for (Agent agent : agents) { + if (agent.getArea().equals(area)) { + result++; + } + } + return result; } - /* #3 * getAgentsInAreaThatSpeakLanguage() -- Return a list of agents from a given area, that speak a certain language. * @param filePath -- Path to file being read in. @@ -53,10 +108,16 @@ 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 agents = readCsvFile(filePath, Agent.class); + List qualifiedAgents = new ArrayList(); + for (Agent agent : agents) { + if (agent.getArea().equals(area) && agent.getLanguage().equals(language)) { + qualifiedAgents.add(agent); + } + } + return qualifiedAgents; } - - + /* #4 * countCustomersFromAreaThatUseAgent() -- Return the number of individuals from an area that use a certain agent. * @param filePath -- Path to file being read in. @@ -65,11 +126,25 @@ public List getAgentsInAreaThatSpeakLanguage(String filePath, String area * @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) { + List customers = readCsvFile(csvFilePaths.get("customerList"), Customer.class); + List agents = readCsvFile(csvFilePaths.get("agentList"), Agent.class); + short result = 0; + for (Customer customer : customers) { + if (customer.getArea().equals(customerArea)) { + int agentId = customer.getAgentId(); + for (Agent agent : agents) { + if (agent.getAgentId() == agentId && agent.getFirstName().equals(agentFirstName) + && agent.getLastName().equals(agentLastName)) { + result++; + } + } + } + } + return result; } - /* #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. @@ -77,10 +152,22 @@ 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 customers = readCsvFile(customerFilePath, Customer.class); + List qualifiedCustomers = new ArrayList(); + for (Customer customer : customers) { + if (customer.getYearsOfService() == yearsOfService) { + qualifiedCustomers.add(customer); + } + } + Comparator compareByPremium = new Comparator() { + public int compare(Customer c1, Customer c2) { + return c1.getTotalMonthlyPremium().compareTo(c2.getTotalMonthlyPremium()); + } + }; + qualifiedCustomers.sort(compareByPremium); + return qualifiedCustomers; } - /* #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. @@ -88,12 +175,18 @@ 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 customers = readCsvFile(filePath, Customer.class); + List qualifiedCustomers = new ArrayList(); + for (Customer customer : customers) { + if (!customer.getAutoPolicy() && !customer.getHomePolicy() && !customer.getRentersPolicy()) { + qualifiedCustomers.add(customer); + } + } + return qualifiedCustomers; } - /* #7 - * getVendorsWithGivenRatingThatAreInScope() -- Return a list of vendors within an area and include options to narrow it down by: + * 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. @@ -102,11 +195,18 @@ b. Whether that vendor is in scope of the insurance (if inScope == false, return * @param vendorRating -- The rating of the vendor. * @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) { + List vendors = readCsvFile(filePath, Vendor.class); + List qualifiedVendors = new ArrayList(); + for (Vendor vendor : vendors) { + if (vendor.getArea().equals(area) && vendor.getVendorRating() >= vendorRating && ((inScope && vendor.getInScope()) || !inScope)) { + qualifiedVendors.add(vendor); + } + } + return qualifiedVendors; } - /* #8 * getUndisclosedDrivers() -- Return a list of customers between the age of 40 and 50 years (inclusive), who have: a. More than X cars @@ -117,31 +217,124 @@ 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 customers = readCsvFile(filePath, Customer.class); + List qualifiedCustomers = new ArrayList(); + for (Customer customer : customers) { + if (customer.getVehiclesInsured() > vehiclesInsured && customer.getAge() >= 40 && customer.getAge() <= 50 + && customer.getDependents().size() <= dependents) { + qualifiedCustomers.add(customer); + } + } + return qualifiedCustomers; + } /* #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 + * 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) { - - } + List customers = readCsvFile(filePath, Customer.class); + Map> ratings = new HashMap>(); + for (Customer customer : customers) { + List agentRatings = ratings.get(customer.getAgentId()); + if (agentRatings == null) { + agentRatings = new ArrayList(); + } + agentRatings.add(customer.getAgentRating()); + ratings.put(customer.getAgentId(), agentRatings); + } + + Iterator>> it = ratings.entrySet().iterator(); + List> averageRatings = new ArrayList>(); + while (it.hasNext()) { + Entry> entry = it.next(); + int sum = 0; + for (Short rating : entry.getValue()) { + sum += rating; + } + float averageRating = sum / (float) entry.getValue().size(); + averageRatings.add(Arrays.asList((float) entry.getKey(), averageRating)); + } + + Comparator> compareByAverageRating = new Comparator>() { + public int compare(List l1, List l2) { + return l2.get(1).compareTo(l1.get(1)); + } + }; + + averageRatings.sort(compareByAverageRating); + return Math.round(averageRatings.get(agentRank - 1).get(0)); + } + - /* #10 - * getCustomersWithClaims() -- Return a list of customers who’ve filed a claim within the last (inclusive). + * 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 . */ public List getCustomersWithClaims(Map csvFilePaths, short monthsOpen) { + List claims = readCsvFile(csvFilePaths.get("claimList"), Claim.class); + List customers = readCsvFile(csvFilePaths.get("customerList"), Customer.class); + Set qualifiedCustomers = new HashSet(); + for (Claim claim : claims) { + if (claim.getMonthsOpen() <= monthsOpen) { + for (Customer customer : customers) { + if (claim.getCustomerId() == customer.getCustomerId()) { + qualifiedCustomers.add(customer); + } + } + } + } + return new ArrayList(qualifiedCustomers); + } - } + /* + * getPossibleVendorsForClaim() -- Return a list of vendors in the area of a given claim. + * @param filePath -- Path to file being read in. + * @param claimId -- ID of an open claim. + * @return -- List of vendors within the area of the claim. + */ + public List getPossibleVendorsForClaim(Map csvFilePaths, int claimId) { + List claims = readCsvFile(csvFilePaths.get("claimList"), Claim.class); + List customers = readCsvFile(csvFilePaths.get("customerList"), Customer.class); + List vendors = readCsvFile(csvFilePaths.get("vendorList"), Vendor.class); + List qualifiedVendors = new ArrayList(); + for (Claim claim : claims) { + if (claim.getClaimId() == claimId && !claim.getClosed()) { + for (Customer customer : customers) { + if (claim.getCustomerId() == customer.getCustomerId()) { + for (Vendor vendor : vendors) { + if (vendor.getArea() == customer.getArea()) { + qualifiedVendors.add(vendor); + } + } + } + } + } + } + return qualifiedVendors; + } + + /* + * countClaimsOpenForMonths() -- Return the number of claims open for a given number of months. + * @param filePath -- Path to file being read in. + * @param monthsOpen -- Number of months a policy has been open. + * @return -- Number claims open for . + */ + public int countClaimsOpenForMonths(String filePath, int monthsOpen) { + List claims = readCsvFile(filePath, Claim.class); + int result = 0; + for (Claim claim : claims) { + if (claim.getMonthsOpen() == monthsOpen && !claim.getClosed()) { + result++; + } + } + return result; + } } diff --git a/src/main/java/sf/codingcompetition2020/GraphPanel.java b/src/main/java/sf/codingcompetition2020/GraphPanel.java new file mode 100644 index 0000000..3070458 --- /dev/null +++ b/src/main/java/sf/codingcompetition2020/GraphPanel.java @@ -0,0 +1,153 @@ +/** + * https://stackoverflow.com/questions/8693342/drawing-a-simple-line-graph-in-java + */ + +package sf.codingcompetition2020; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.RenderingHints; +import java.awt.Stroke; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +public class GraphPanel extends JPanel { + private int width = 800; + private int heigth = 400; + private int padding = 25; + private int labelPadding = 25; + private Color lineColor = new Color(44, 102, 230, 180); + private Color pointColor = new Color(100, 100, 100, 180); + private Color gridColor = new Color(200, 200, 200, 200); + private static final Stroke GRAPH_STROKE = new BasicStroke(2f); + private int pointWidth = 4; + private int numberYDivisions = 10; + private List scores; + + public GraphPanel(List scores) { + this.scores = scores; + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + double xScale = ((double) getWidth() - (2 * padding) - labelPadding) / (scores.size() - 1); + double yScale = ((double) getHeight() - 2 * padding - labelPadding) / (getMaxScore()); + + List graphPoints = new ArrayList(); + for (int i = 0; i < scores.size(); i++) { + int x1 = (int) (i * xScale + padding + labelPadding); + int y1 = (int) ((getMaxScore() - scores.get(i)) * yScale + padding); + graphPoints.add(new Point(x1, y1)); + } + + // draw white background + g2.setColor(Color.WHITE); + g2.fillRect(padding + labelPadding, padding, getWidth() - (2 * padding) - labelPadding, getHeight() - 2 * padding - labelPadding); + g2.setColor(Color.BLACK); + + // create hatch marks and grid lines for y axis. + for (int i = 0; i < numberYDivisions + 1; i++) { + int x0 = padding + labelPadding; + int x1 = pointWidth + padding + labelPadding; + int y0 = getHeight() - ((i * (getHeight() - padding * 2 - labelPadding)) / numberYDivisions + padding + labelPadding); + int y1 = y0; + if (scores.size() > 0) { + g2.setColor(gridColor); + g2.drawLine(padding + labelPadding + 1 + pointWidth, y0, getWidth() - padding, y1); + g2.setColor(Color.BLACK); + String yLabel = ((int) ((getMaxScore() * ((i * 1.0) / numberYDivisions)) * 100)) / 100.0 + ""; + FontMetrics metrics = g2.getFontMetrics(); + int labelWidth = metrics.stringWidth(yLabel); + g2.drawString(yLabel, x0 - labelWidth - 5, y0 + (metrics.getHeight() / 2) - 3); + } + g2.drawLine(x0, y0, x1, y1); + } + + // and for x axis + for (int i = 0; i < scores.size(); i++) { + if (scores.size() > 1) { + int x0 = i * (getWidth() - padding * 2 - labelPadding) / (scores.size() - 1) + padding + labelPadding; + int x1 = x0; + int y0 = getHeight() - padding - labelPadding; + int y1 = y0 - pointWidth; + if ((i % ((int) ((scores.size() / 20.0)) + 1)) == 0) { + g2.setColor(gridColor); + g2.drawLine(x0, getHeight() - padding - labelPadding - 1 - pointWidth, x1, padding); + g2.setColor(Color.BLACK); + String xLabel = i + 1 + ""; + FontMetrics metrics = g2.getFontMetrics(); + int labelWidth = metrics.stringWidth(xLabel); + g2.drawString(xLabel, x0 - labelWidth / 2, y0 + metrics.getHeight() + 3); + } + g2.drawLine(x0, y0, x1, y1); + } + } + + // create x and y axes + g2.drawLine(padding + labelPadding, getHeight() - padding - labelPadding, padding + labelPadding, padding); + g2.drawLine(padding + labelPadding, getHeight() - padding - labelPadding, getWidth() - padding, getHeight() - padding - labelPadding); + + Stroke oldStroke = g2.getStroke(); + g2.setColor(lineColor); + g2.setStroke(GRAPH_STROKE); + for (int i = 0; i < graphPoints.size() - 1; i++) { + int x1 = graphPoints.get(i).x; + int y1 = graphPoints.get(i).y; + int x2 = graphPoints.get(i + 1).x; + int y2 = graphPoints.get(i + 1).y; + g2.drawLine(x1, y1, x2, y2); + } + + g2.setStroke(oldStroke); + g2.setColor(pointColor); + for (int i = 0; i < graphPoints.size(); i++) { + int x = graphPoints.get(i).x - pointWidth / 2; + int y = graphPoints.get(i).y - pointWidth / 2; + int ovalW = pointWidth; + int ovalH = pointWidth; + g2.fillOval(x, y, ovalW, ovalH); + } + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(width, heigth); + } + private double getMinScore() { + double minScore = Double.MAX_VALUE; + for (Double score : scores) { + minScore = Math.min(minScore, score); + } + return minScore; + } + + private double getMaxScore() { + double maxScore = Double.MIN_VALUE; + for (Double score : scores) { + maxScore = Math.max(maxScore, score); + } + return maxScore; + } + + public void setScores(List scores) { + this.scores = scores; + invalidate(); + this.repaint(); + } + + public List getScores() { + return scores; + } +} diff --git a/src/main/java/sf/codingcompetition2020/Gui.java b/src/main/java/sf/codingcompetition2020/Gui.java new file mode 100644 index 0000000..a0338d5 --- /dev/null +++ b/src/main/java/sf/codingcompetition2020/Gui.java @@ -0,0 +1,52 @@ +package sf.codingcompetition2020; + +import java.util.List; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JLabel; +import java.awt.Dimension; +import java.awt.BorderLayout; +import java.util.ArrayList; + +public class Gui extends JPanel { + public Gui(String title, List points) { + setLayout(new BorderLayout()); + JLabel titleL = new JLabel(title); + titleL.setHorizontalAlignment(JLabel.CENTER); + add(titleL, BorderLayout.NORTH); + GraphPanel graphPanel = new GraphPanel(points); + graphPanel.setPreferredSize(new Dimension(800, 600)); + add(graphPanel, BorderLayout.CENTER); + } + + public static void main(String[] args) { + CodingCompCsvUtil util = new CodingCompCsvUtil(); + + String title1 = "Claims Open for n Months"; + List claimCounts = new ArrayList(); + String claimsPath = "src/main/resources/DataFiles/claims.csv"; + for (int i = 1; i <= 12; i++) { + claimCounts.add((double) util.countClaimsOpenForMonths(claimsPath, i)); + } + JFrame frame1 = new JFrame(title1); + frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame1.getContentPane().add(new Gui(title1, claimCounts)); + frame1.pack(); + frame1.setLocationRelativeTo(null); + frame1.setVisible(true); + + String title2 = "Agent Count in Area i"; + String agentsPath = "src/main/resources/DataFiles/agents.csv"; + List agentCount = new ArrayList(); + for (int i = 1; i <= 5; i++) { + String area = "area-" + i; + agentCount.add((double) util.getAgentCountInArea(agentsPath, area)); + } + JFrame frame2 = new JFrame(title2); + frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame2.getContentPane().add(new Gui(title2, agentCount)); + frame2.pack(); + frame2.setLocationRelativeTo(null); + frame2.setVisible(true); + } +} diff --git a/src/main/java/sf/codingcompetition2020/structures/Agent.java b/src/main/java/sf/codingcompetition2020/structures/Agent.java index e2e6f93..65a4634 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Agent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Agent.java @@ -1,11 +1,35 @@ package sf.codingcompetition2020.structures; public class Agent { - + private int agentId; private String area; 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; + } + } diff --git a/src/main/java/sf/codingcompetition2020/structures/Claim.java b/src/main/java/sf/codingcompetition2020/structures/Claim.java index 581140a..35cc43d 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Claim.java +++ b/src/main/java/sf/codingcompetition2020/structures/Claim.java @@ -5,5 +5,24 @@ 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 boolean getClosed() { + return closed; + } + public int getMonthsOpen() { + return monthsOpen; + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Customer.java b/src/main/java/sf/codingcompetition2020/structures/Customer.java index f151906..4ce0a0b 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Customer.java +++ b/src/main/java/sf/codingcompetition2020/structures/Customer.java @@ -24,4 +24,67 @@ 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 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 getHomePolicy() { + return homePolicy; + } + public boolean getAutoPolicy() { + return autoPolicy; + } + public boolean getRentersPolicy() { + 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..16aa45c 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Dependent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Dependent.java @@ -4,4 +4,15 @@ public class Dependent { private String firstName; private String lastName; + public Dependent(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName(){ + return firstName; + } + public String getLastName(){ + return lastName; + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Vendor.java b/src/main/java/sf/codingcompetition2020/structures/Vendor.java index 6b6fb76..f47470e 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Vendor.java +++ b/src/main/java/sf/codingcompetition2020/structures/Vendor.java @@ -5,5 +5,24 @@ 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 int getVendorId() { + return vendorId; + } + public String getArea() { + return area; + } + public int getVendorRating() { + return vendorRating; + } + public boolean getInScope() { + return inScope; + } } diff --git a/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java b/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java index c29959f..ed6cfbc 100644 --- a/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java +++ b/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java @@ -13,7 +13,7 @@ import sf.codingcompetition2020.structures.Customer; public class CodingCompCsvUtilTest{ - + private final String agentFilePath = "src/main/resources/DataFiles/agents.csv"; private final String claimFilePath = "src/main/resources/DataFiles/claims.csv"; private final String customerFilePath = "src/main/resources/DataFiles/customers.csv"; @@ -21,10 +21,10 @@ public class CodingCompCsvUtilTest{ private final String agentList = "agentList"; private final String claimList = "claimList"; private final String customerList = "customerList"; - - + + CodingCompCsvUtil codingCompCsVUtil = new CodingCompCsvUtil(); - + //#1 @Test public void test1() { @@ -32,14 +32,14 @@ public void test1() { assertEquals(424, ((Claim)codingCompCsVUtil.readCsvFile(claimFilePath, Claim.class).get(423)).getClaimId()); assertEquals("Lorin", ((Customer)codingCompCsVUtil.readCsvFile(customerFilePath, Customer.class).get(499)).getFirstName()); } - + //#2 @Test public void getAgentCountInArea() { assertEquals(247,codingCompCsVUtil.getAgentCountInArea(agentFilePath, "area-4")); assertEquals(55,codingCompCsVUtil.getAgentCountInArea(agentFilePath, "area-2")); } - + //#3 @Test public void getAgentsInAreaThatSpeakLanguage() { @@ -47,29 +47,29 @@ public void getAgentsInAreaThatSpeakLanguage() { assertEquals(2, agentList.size()); assertEquals(49, agentList.get(0).getAgentId()); assertEquals(424, agentList.get(1).getAgentId()); - + agentList = codingCompCsVUtil.getAgentsInAreaThatSpeakLanguage(agentFilePath, "area-2", "Spanish"); assertEquals(1, agentList.size()); assertEquals(242, agentList.get(0).getAgentId()); } - + //#4 @Test public void countCustomersFromCitythatUseAgent() { - Map csvFilePaths = new HashMap<>(); - + Map csvFilePaths = new HashMap(); + csvFilePaths.put(agentList, agentFilePath); csvFilePaths.put(customerList, customerFilePath); assertEquals(4,codingCompCsVUtil.countCustomersFromAreaThatUseAgent(csvFilePaths, "area-3", "Piggy","Ferrai")); assertEquals(6,codingCompCsVUtil.countCustomersFromAreaThatUseAgent(csvFilePaths, "area-4", "Rabi","Figg")); } - + //#5 @Test public void getCustomersRetainedForYearsByPlcyCostAsc() { List customerList = codingCompCsVUtil.getCustomersRetainedForYearsByPlcyCostAsc(customerFilePath, Short.valueOf("5")); - + assertEquals(15,customerList.size()); assertEquals(215,customerList.get(0).getCustomerId()); assertEquals(5,customerList.get(2).getYearsOfService()); @@ -78,13 +78,13 @@ public void getCustomersRetainedForYearsByPlcyCostAsc() { assertEquals("Tesoe",customerList.get(5).getLastName()); assertEquals("$888",customerList.get(14).getTotalMonthlyPremium()); } - + //#6 @Test public void getLeadsForInsurance() { assertEquals(82, codingCompCsVUtil.getLeadsForInsurance(customerFilePath).size()); } - + //#7 @Test public void getVendorsWithGivenRatingThatAreInScope() { @@ -92,33 +92,32 @@ public void getVendorsWithGivenRatingThatAreInScope() { assertEquals(2, codingCompCsVUtil.getVendorsWithGivenRatingThatAreInScope(vendorFilePath, "area-2", true, 2).size()); assertEquals(12, codingCompCsVUtil.getVendorsWithGivenRatingThatAreInScope(vendorFilePath, "area-3", false, 3).size()); } - + //#8 @Test - public void getCustomersRetainedForYearsByPlcyCostAsc2() { + public void getCustomersRetainedForYearsByPlcyCostAsc2() { assertEquals(15,codingCompCsVUtil.getUndisclosedDrivers(customerFilePath,2,2).size()); assertEquals(14,codingCompCsVUtil.getUndisclosedDrivers(customerFilePath,3,3).size()); } - + //#9 @Test - public void getAgentIdGivenRank() { + public void getAgentIdGivenRank() { assertEquals(3,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 1)); assertEquals(12,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 4)); assertEquals(14,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 20)); } - + //#10 @Test public void getCountCustomersWithClaims() { - Map csvFilePaths = new HashMap<>(); - + Map csvFilePaths = new HashMap(); + csvFilePaths.put(customerList, customerFilePath); csvFilePaths.put(claimList, claimFilePath); - + assertEquals(81,codingCompCsVUtil.getCustomersWithClaims(csvFilePaths, Short.valueOf("1")).size()); assertEquals(312,codingCompCsVUtil.getCustomersWithClaims(csvFilePaths, Short.valueOf("6")).size()); } } - diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF deleted file mode 100644 index e2a1a34..0000000 --- a/target/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,5 +0,0 @@ -Manifest-Version: 1.0 -Built-By: yc1d -Build-Jdk: 1.8.0_201 -Created-By: Maven Integration for Eclipse - diff --git a/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.properties b/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.properties deleted file mode 100644 index fe569e3..0000000 --- a/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.properties +++ /dev/null @@ -1,7 +0,0 @@ -#Generated by Maven Integration for Eclipse -#Thu Oct 08 09:27:33 MST 2020 -version=1.0.0-SNAPSHOT -groupId=sf.codingcompetition2020 -m2e.projectName=coding-competition -m2e.projectLocation=/Users/yc1d/Development/coding-competition/problem/online-competition -artifactId=coding-competition diff --git a/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.xml b/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.xml deleted file mode 100644 index 21d55bf..0000000 --- a/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - 4.0.0 - coding-competition - 1.0.0-SNAPSHOT - jar - sf.codingcompetition2020 - - coding-competition - Coding Competition - - - - - - - junit - junit - 4.12 - test - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-csv - 2.11.2 - - - - diff --git a/target/classes/sf/codingcompetition2020/CodingCompCsvUtil$1.class b/target/classes/sf/codingcompetition2020/CodingCompCsvUtil$1.class new file mode 100644 index 0000000..9432484 Binary files /dev/null and b/target/classes/sf/codingcompetition2020/CodingCompCsvUtil$1.class differ diff --git a/target/classes/sf/codingcompetition2020/CodingCompCsvUtil$2.class b/target/classes/sf/codingcompetition2020/CodingCompCsvUtil$2.class new file mode 100644 index 0000000..eeb6919 Binary files /dev/null and b/target/classes/sf/codingcompetition2020/CodingCompCsvUtil$2.class differ diff --git a/target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class b/target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class index 00daba9..2d50e87 100644 Binary files a/target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class and b/target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class differ diff --git a/target/classes/sf/codingcompetition2020/GraphPanel.class b/target/classes/sf/codingcompetition2020/GraphPanel.class new file mode 100644 index 0000000..d7d8ab5 Binary files /dev/null and b/target/classes/sf/codingcompetition2020/GraphPanel.class differ diff --git a/target/classes/sf/codingcompetition2020/Gui.class b/target/classes/sf/codingcompetition2020/Gui.class new file mode 100644 index 0000000..5e08715 Binary files /dev/null and b/target/classes/sf/codingcompetition2020/Gui.class differ diff --git a/target/classes/sf/codingcompetition2020/structures/Agent.class b/target/classes/sf/codingcompetition2020/structures/Agent.class index 26bf31f..2903afd 100644 Binary files a/target/classes/sf/codingcompetition2020/structures/Agent.class and b/target/classes/sf/codingcompetition2020/structures/Agent.class differ diff --git a/target/classes/sf/codingcompetition2020/structures/Claim.class b/target/classes/sf/codingcompetition2020/structures/Claim.class index 1ce796d..9e57390 100644 Binary files a/target/classes/sf/codingcompetition2020/structures/Claim.class and b/target/classes/sf/codingcompetition2020/structures/Claim.class differ diff --git a/target/classes/sf/codingcompetition2020/structures/Customer.class b/target/classes/sf/codingcompetition2020/structures/Customer.class index 844ea29..7a8a241 100644 Binary files a/target/classes/sf/codingcompetition2020/structures/Customer.class and b/target/classes/sf/codingcompetition2020/structures/Customer.class differ diff --git a/target/classes/sf/codingcompetition2020/structures/Dependent.class b/target/classes/sf/codingcompetition2020/structures/Dependent.class index 3ee505f..4d8d6a1 100644 Binary files a/target/classes/sf/codingcompetition2020/structures/Dependent.class and b/target/classes/sf/codingcompetition2020/structures/Dependent.class differ diff --git a/target/classes/sf/codingcompetition2020/structures/Vendor.class b/target/classes/sf/codingcompetition2020/structures/Vendor.class index fdbca9b..42d9a1c 100644 Binary files a/target/classes/sf/codingcompetition2020/structures/Vendor.class and b/target/classes/sf/codingcompetition2020/structures/Vendor.class differ diff --git a/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class b/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class index 765ac60..4dbfcea 100644 Binary files a/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class and b/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class differ