diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..92be83e
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text eol=crlf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a8236da
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+.idea
+.idea/**/*
+
+*.iml
+
+target
+target/**/*
\ No newline at end of file
diff --git a/feedback.txt b/feedback.txt
index b931d50..66886ca 100644
--- a/feedback.txt
+++ b/feedback.txt
@@ -1,9 +1,26 @@
-Your team (name of each individual participating):
-How many JUnits were you able to get to pass?
+Your team (name of each individual participating): Mudit Gupta, Manoj Niverthi
+How many JUnits were you able to get to pass? 10
Document and describe any enhancements included to help the judges properly grade your submission.
- Step 1:
- Step 2:
+ Step 1: We used Checkstyle to make sure the code was readable according to publicly agreed upon standards.
+ Step 2: We made all fileIO related methods and tests throw IOException to account for when a file is not found.
+ If a file is not found, is does not make sense to just return an empty list, as we should instead tell the user that they are attempting to read a non-present file.
+ We also changed some of the tests to throw the IOException.
+ Step 3: We noticed that the vehiclesInsured field was unnecessarily declared as an Integer in the Customer class, so we converted it to an int.
+ Step 4: The Customer class was using a String for the totalMonthlyPremium because of a dollar sign, so we converted it to an int.
+ This makes future use of the value much more intuitive and meaningful.
+ We also updated the test values in the JUnit to reflect the better implementation.
+ Step 5: We improved the javadocs for all of the provided methods to make their use easier.
+ We also generated the javadoc HTML for this project, so that they can be more easily referenced. These can be found in javadocs/index.html
+ Step 6: We created 2 methods in the CsvUtil class that can be used to find other patterns in the data.
+ We created getCustomersBasedOnNumberOfPolicies and getVendorsForCustomerBasedOnArea.
+ We also created tests for these two methods.
+ Step 7: We implemented the Builder pattern for each of the data classes. Although unused for this implementation, builders are a very helpful design pattern to use when a constructor has many hard-to-remember parameters.
+ If a user wanted to add functionality for creating objects and writing to CSV, rather than reading, the builder would prove very valuable for code readability/maintainability.
Feedback for the coding competition? Things you would like to see in future events?
+Some of the requirements in the javadocs wre a bit unclear.
+ For #5, we had to do customer.getYearsOfService() == yearsOfService
+ But for #7, we had to do vendor.getVendorRating() >= vendorRating
+ Whether or not we use > or == was a bit unclear and required us to guess as to why the tests failed.
\ No newline at end of file
diff --git a/javadocs/allclasses-frame.html b/javadocs/allclasses-frame.html
new file mode 100644
index 0000000..9e0937b
--- /dev/null
+++ b/javadocs/allclasses-frame.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+All Classes
+
+
+
+
+
+All Classes
+
+
+
diff --git a/javadocs/allclasses-noframe.html b/javadocs/allclasses-noframe.html
new file mode 100644
index 0000000..9a3cc03
--- /dev/null
+++ b/javadocs/allclasses-noframe.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+All Classes
+
+
+
+
+
+All Classes
+
+
+
diff --git a/javadocs/constant-values.html b/javadocs/constant-values.html
new file mode 100644
index 0000000..8c76a1b
--- /dev/null
+++ b/javadocs/constant-values.html
@@ -0,0 +1,120 @@
+
+
+
+
+
+Constant Field Values
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadocs/deprecated-list.html b/javadocs/deprecated-list.html
new file mode 100644
index 0000000..7408fbc
--- /dev/null
+++ b/javadocs/deprecated-list.html
@@ -0,0 +1,120 @@
+
+
+
+
+
+Deprecated List
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadocs/help-doc.html b/javadocs/help-doc.html
new file mode 100644
index 0000000..c38a898
--- /dev/null
+++ b/javadocs/help-doc.html
@@ -0,0 +1,217 @@
+
+
+
+
+
+API Help
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+Package
+Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:
+
+Interfaces (italic)
+Classes
+Enums
+Exceptions
+Errors
+Annotation Types
+
+
+
+Class/Interface
+Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
+
+Class inheritance diagram
+Direct Subclasses
+All Known Subinterfaces
+All Known Implementing Classes
+Class/interface declaration
+Class/interface description
+
+
+Nested Class Summary
+Field Summary
+Constructor Summary
+Method Summary
+
+
+Field Detail
+Constructor Detail
+Method Detail
+
+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
+
+
+Annotation Type
+Each annotation type has its own separate page with the following sections:
+
+Annotation Type declaration
+Annotation Type description
+Required Element Summary
+Optional Element Summary
+Element Detail
+
+
+
+Enum
+Each enum has its own separate page with the following sections:
+
+Enum declaration
+Enum description
+Enum Constant Summary
+Enum Constant Detail
+
+
+
+Tree (Class Hierarchy)
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
+
+When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
+When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
+
+
+
+Deprecated API
+The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
+
+
+Index
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
+
+
+Prev/Next
+These links take you to the next or previous class, interface, package, or related page.
+
+
+Frames/No Frames
+These links show and hide the HTML frames. All pages are available with or without frames.
+
+
+All Classes
+The All Classes link shows all classes and interfaces except non-static nested types.
+
+
+Serialized Form
+Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
+
+
+Constant Field Values
+The Constant Field Values page lists the static final fields and their values.
+
+
+
This help file applies to API documentation generated using the standard doclet.
+
+
+
+
+
+
diff --git a/javadocs/index-all.html b/javadocs/index-all.html
new file mode 100644
index 0000000..dde02a7
--- /dev/null
+++ b/javadocs/index-all.html
@@ -0,0 +1,177 @@
+
+
+
+
+
+Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+C G R S
+
+
+
C
+
+CodingCompCsvUtil - Class in sf.codingcompetition2020
+
+This class processes CSV data related to Insurance policy data.
+
+CodingCompCsvUtil() - Constructor for class sf.codingcompetition2020.CodingCompCsvUtil
+
+countCustomersFromAreaThatUseAgent(Map<String, String>, String, String, String) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+
+
+
+
+
G
+
+getAgentCountInArea(String, String) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+Return the number of agents in a given area.
+
+getAgentIdGivenRank(String, int) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+getAgentsInAreaThatSpeakLanguage(String, String, String) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+getCustomersBasedOnNumberOfPolicies(String, int) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+getCustomersRetainedForYearsByPlcyCostAsc(String, short) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+getCustomersWithClaims(Map<String, String>, short) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+getLeadsForInsurance(String) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+getUndisclosedDrivers(String, int, int) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+getVendorsForCustomerBasedOnArea(Map<String, String>, String, String) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+getVendorsWithGivenRatingThatAreInScope(String, String, boolean, int) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+
+
+
+
+
R
+
+readCsvFile(String, Class<T>) - Method in class sf.codingcompetition2020.CodingCompCsvUtil
+
+Read in a CSV File and return a list of entries in that file.
+
+
+
+
+
+
S
+
+sf.codingcompetition2020 - package sf.codingcompetition2020
+
+
+
C G R S
+
+
+
+
+
+
diff --git a/javadocs/index.html b/javadocs/index.html
new file mode 100644
index 0000000..f7a0427
--- /dev/null
+++ b/javadocs/index.html
@@ -0,0 +1,72 @@
+
+
+
+
+
+Generated Documentation (Untitled)
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+Frame Alert
+This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
+
+
+
diff --git a/javadocs/overview-tree.html b/javadocs/overview-tree.html
new file mode 100644
index 0000000..e264aa2
--- /dev/null
+++ b/javadocs/overview-tree.html
@@ -0,0 +1,133 @@
+
+
+
+
+
+Class Hierarchy
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadocs/package-list b/javadocs/package-list
new file mode 100644
index 0000000..bb3c9f5
--- /dev/null
+++ b/javadocs/package-list
@@ -0,0 +1 @@
+sf.codingcompetition2020
diff --git a/javadocs/script.js b/javadocs/script.js
new file mode 100644
index 0000000..b346356
--- /dev/null
+++ b/javadocs/script.js
@@ -0,0 +1,30 @@
+function show(type)
+{
+ count = 0;
+ for (var key in methods) {
+ var row = document.getElementById(key);
+ if ((methods[key] & type) != 0) {
+ row.style.display = '';
+ row.className = (count++ % 2) ? rowColor : altColor;
+ }
+ else
+ row.style.display = 'none';
+ }
+ updateTabs(type);
+}
+
+function updateTabs(type)
+{
+ for (var value in tabs) {
+ var sNode = document.getElementById(tabs[value][0]);
+ var spanNode = sNode.firstChild;
+ if (value == type) {
+ sNode.className = activeTableTab;
+ spanNode.innerHTML = tabs[value][1];
+ }
+ else {
+ sNode.className = tableTab;
+ spanNode.innerHTML = "" + tabs[value][1] + " ";
+ }
+ }
+}
diff --git a/javadocs/sf/codingcompetition2020/CodingCompCsvUtil.html b/javadocs/sf/codingcompetition2020/CodingCompCsvUtil.html
new file mode 100644
index 0000000..67ce7f9
--- /dev/null
+++ b/javadocs/sf/codingcompetition2020/CodingCompCsvUtil.html
@@ -0,0 +1,525 @@
+
+
+
+
+
+CodingCompCsvUtil
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+Prev Class
+Next Class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+java.lang.Object
+
+
+sf.codingcompetition2020.CodingCompCsvUtil
+
+
+
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+
+
+
+
+
+
+
+Method Summary
+
+All Methods Instance Methods Concrete Methods
+
+Modifier and Type
+Method and Description
+
+
+short
+countCustomersFromAreaThatUseAgent (java.util.Map<java.lang.String,java.lang.String> csvFilePaths,
+ java.lang.String customerArea,
+ java.lang.String agentFirstName,
+ java.lang.String agentLastName)
+
+
+int
+getAgentCountInArea (java.lang.String filePath,
+ java.lang.String area)
+Return the number of agents in a given area.
+
+
+
+int
+getAgentIdGivenRank (java.lang.String filePath,
+ int agentRank)
+
+
+java.util.List<sf.codingcompetition2020.structures.Agent>
+getAgentsInAreaThatSpeakLanguage (java.lang.String filePath,
+ java.lang.String area,
+ java.lang.String language)
+
+
+java.util.List<sf.codingcompetition2020.structures.Customer>
+getCustomersBasedOnNumberOfPolicies (java.lang.String filePath,
+ int numberOfPolicies)
+
+
+java.util.List<sf.codingcompetition2020.structures.Customer>
+getCustomersRetainedForYearsByPlcyCostAsc (java.lang.String customerFilePath,
+ short yearsOfService)
+
+
+java.util.List<sf.codingcompetition2020.structures.Customer>
+getCustomersWithClaims (java.util.Map<java.lang.String,java.lang.String> csvFilePaths,
+ short monthsOpen)
+
+
+java.util.List<sf.codingcompetition2020.structures.Customer>
+getLeadsForInsurance (java.lang.String filePath)
+
+
+java.util.List<sf.codingcompetition2020.structures.Customer>
+getUndisclosedDrivers (java.lang.String filePath,
+ int vehiclesInsured,
+ int dependents)
+
+
+java.util.List<sf.codingcompetition2020.structures.Vendor>
+getVendorsForCustomerBasedOnArea (java.util.Map<java.lang.String,java.lang.String> csvFilePaths,
+ java.lang.String customerFirstName,
+ java.lang.String customerLastName)
+
+
+java.util.List<sf.codingcompetition2020.structures.Vendor>
+getVendorsWithGivenRatingThatAreInScope (java.lang.String filePath,
+ java.lang.String area,
+ boolean inScope,
+ int vendorRating)
+
+
+<T> java.util.List<T>
+readCsvFile (java.lang.String filePath,
+ java.lang.Class<T> classType)
+Read in a CSV File and return a list of entries in that file.
+
+
+
+
+
+
+
+Methods inherited from class java.lang.Object
+clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Constructor Detail
+
+
+
+
+
+
+
+
+
+
+
+Method Detail
+
+
+
+
+
+readCsvFile
+public <T> java.util.List<T> readCsvFile(java.lang.String filePath,
+ java.lang.Class<T> classType)
+ throws java.io.IOException
+Read in a CSV File and return a list of entries in that file.
+
+Type Parameters:
+T - Type of Object to parse
+Parameters:
+filePath - Path to file being read in.
+classType - Class of entries being read in.
+Returns:
+List of entries being returned.
+Throws:
+java.io.IOException
+
+
+
+
+
+
+
+
+getAgentCountInArea
+public int getAgentCountInArea(java.lang.String filePath,
+ java.lang.String area)
+ throws java.io.IOException
+Return the number of agents in a given area.
+
+Parameters:
+filePath - Path to file being read in.
+area - The area from which the agents should be counted.
+Returns:
+The number of agents in a given area
+Throws:
+java.io.IOException - If file is interpreted incorrectly
+
+
+
+
+
+
+
+
+getAgentsInAreaThatSpeakLanguage
+public java.util.List<sf.codingcompetition2020.structures.Agent> getAgentsInAreaThatSpeakLanguage(java.lang.String filePath,
+ java.lang.String area,
+ java.lang.String language)
+ throws java.io.IOException
+
+Throws:
+java.io.IOException
+
+
+
+
+
+
+
+
+countCustomersFromAreaThatUseAgent
+public short countCustomersFromAreaThatUseAgent(java.util.Map<java.lang.String,java.lang.String> csvFilePaths,
+ java.lang.String customerArea,
+ java.lang.String agentFirstName,
+ java.lang.String agentLastName)
+ throws java.io.IOException
+
+Throws:
+java.io.IOException
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+getVendorsWithGivenRatingThatAreInScope
+public java.util.List<sf.codingcompetition2020.structures.Vendor> getVendorsWithGivenRatingThatAreInScope(java.lang.String filePath,
+ java.lang.String area,
+ boolean inScope,
+ int vendorRating)
+ throws java.io.IOException
+
+Throws:
+java.io.IOException
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+getCustomersWithClaims
+public java.util.List<sf.codingcompetition2020.structures.Customer> getCustomersWithClaims(java.util.Map<java.lang.String,java.lang.String> csvFilePaths,
+ short monthsOpen)
+ throws java.io.IOException
+
+Throws:
+java.io.IOException
+
+
+
+
+
+
+
+
+
+
+
+
+getVendorsForCustomerBasedOnArea
+public java.util.List<sf.codingcompetition2020.structures.Vendor> getVendorsForCustomerBasedOnArea(java.util.Map<java.lang.String,java.lang.String> csvFilePaths,
+ java.lang.String customerFirstName,
+ java.lang.String customerLastName)
+ throws java.io.IOException
+
+Throws:
+java.io.IOException
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Prev Class
+Next Class
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadocs/sf/codingcompetition2020/package-frame.html b/javadocs/sf/codingcompetition2020/package-frame.html
new file mode 100644
index 0000000..0f6a31f
--- /dev/null
+++ b/javadocs/sf/codingcompetition2020/package-frame.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+sf.codingcompetition2020
+
+
+
+
+
+
+
+
+
diff --git a/javadocs/sf/codingcompetition2020/package-summary.html b/javadocs/sf/codingcompetition2020/package-summary.html
new file mode 100644
index 0000000..62ba5d0
--- /dev/null
+++ b/javadocs/sf/codingcompetition2020/package-summary.html
@@ -0,0 +1,140 @@
+
+
+
+
+
+sf.codingcompetition2020
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+Prev Package
+Next Package
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Class Summary
+
+Class
+Description
+
+
+
+CodingCompCsvUtil
+
+This class processes CSV data related to Insurance policy data.
+
+
+
+
+
+
+
+
+
+
+
+Prev Package
+Next Package
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadocs/sf/codingcompetition2020/package-tree.html b/javadocs/sf/codingcompetition2020/package-tree.html
new file mode 100644
index 0000000..b519827
--- /dev/null
+++ b/javadocs/sf/codingcompetition2020/package-tree.html
@@ -0,0 +1,129 @@
+
+
+
+
+
+sf.codingcompetition2020 Class Hierarchy
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadocs/stylesheet.css b/javadocs/stylesheet.css
new file mode 100644
index 0000000..98055b2
--- /dev/null
+++ b/javadocs/stylesheet.css
@@ -0,0 +1,574 @@
+/* Javadoc style sheet */
+/*
+Overall document style
+*/
+
+@import url('resources/fonts/dejavu.css');
+
+body {
+ background-color:#ffffff;
+ color:#353833;
+ font-family:'DejaVu Sans', Arial, Helvetica, sans-serif;
+ font-size:14px;
+ margin:0;
+}
+a:link, a:visited {
+ text-decoration:none;
+ color:#4A6782;
+}
+a:hover, a:focus {
+ text-decoration:none;
+ color:#bb7a2a;
+}
+a:active {
+ text-decoration:none;
+ color:#4A6782;
+}
+a[name] {
+ color:#353833;
+}
+a[name]:hover {
+ text-decoration:none;
+ color:#353833;
+}
+pre {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+}
+h1 {
+ font-size:20px;
+}
+h2 {
+ font-size:18px;
+}
+h3 {
+ font-size:16px;
+ font-style:italic;
+}
+h4 {
+ font-size:13px;
+}
+h5 {
+ font-size:12px;
+}
+h6 {
+ font-size:11px;
+}
+ul {
+ list-style-type:disc;
+}
+code, tt {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+ padding-top:4px;
+ margin-top:8px;
+ line-height:1.4em;
+}
+dt code {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+ padding-top:4px;
+}
+table tr td dt code {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+ vertical-align:top;
+ padding-top:4px;
+}
+sup {
+ font-size:8px;
+}
+/*
+Document title and Copyright styles
+*/
+.clear {
+ clear:both;
+ height:0px;
+ overflow:hidden;
+}
+.aboutLanguage {
+ float:right;
+ padding:0px 21px;
+ font-size:11px;
+ z-index:200;
+ margin-top:-9px;
+}
+.legalCopy {
+ margin-left:.5em;
+}
+.bar a, .bar a:link, .bar a:visited, .bar a:active {
+ color:#FFFFFF;
+ text-decoration:none;
+}
+.bar a:hover, .bar a:focus {
+ color:#bb7a2a;
+}
+.tab {
+ background-color:#0066FF;
+ color:#ffffff;
+ padding:8px;
+ width:5em;
+ font-weight:bold;
+}
+/*
+Navigation bar styles
+*/
+.bar {
+ background-color:#4D7A97;
+ color:#FFFFFF;
+ padding:.8em .5em .4em .8em;
+ height:auto;/*height:1.8em;*/
+ font-size:11px;
+ margin:0;
+}
+.topNav {
+ background-color:#4D7A97;
+ color:#FFFFFF;
+ float:left;
+ padding:0;
+ width:100%;
+ clear:right;
+ height:2.8em;
+ padding-top:10px;
+ overflow:hidden;
+ font-size:12px;
+}
+.bottomNav {
+ margin-top:10px;
+ background-color:#4D7A97;
+ color:#FFFFFF;
+ float:left;
+ padding:0;
+ width:100%;
+ clear:right;
+ height:2.8em;
+ padding-top:10px;
+ overflow:hidden;
+ font-size:12px;
+}
+.subNav {
+ background-color:#dee3e9;
+ float:left;
+ width:100%;
+ overflow:hidden;
+ font-size:12px;
+}
+.subNav div {
+ clear:left;
+ float:left;
+ padding:0 0 5px 6px;
+ text-transform:uppercase;
+}
+ul.navList, ul.subNavList {
+ float:left;
+ margin:0 25px 0 0;
+ padding:0;
+}
+ul.navList li{
+ list-style:none;
+ float:left;
+ padding: 5px 6px;
+ text-transform:uppercase;
+}
+ul.subNavList li{
+ list-style:none;
+ float:left;
+}
+.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited {
+ color:#FFFFFF;
+ text-decoration:none;
+ text-transform:uppercase;
+}
+.topNav a:hover, .bottomNav a:hover {
+ text-decoration:none;
+ color:#bb7a2a;
+ text-transform:uppercase;
+}
+.navBarCell1Rev {
+ background-color:#F8981D;
+ color:#253441;
+ margin: auto 5px;
+}
+.skipNav {
+ position:absolute;
+ top:auto;
+ left:-9999px;
+ overflow:hidden;
+}
+/*
+Page header and footer styles
+*/
+.header, .footer {
+ clear:both;
+ margin:0 20px;
+ padding:5px 0 0 0;
+}
+.indexHeader {
+ margin:10px;
+ position:relative;
+}
+.indexHeader span{
+ margin-right:15px;
+}
+.indexHeader h1 {
+ font-size:13px;
+}
+.title {
+ color:#2c4557;
+ margin:10px 0;
+}
+.subTitle {
+ margin:5px 0 0 0;
+}
+.header ul {
+ margin:0 0 15px 0;
+ padding:0;
+}
+.footer ul {
+ margin:20px 0 5px 0;
+}
+.header ul li, .footer ul li {
+ list-style:none;
+ font-size:13px;
+}
+/*
+Heading styles
+*/
+div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 {
+ background-color:#dee3e9;
+ border:1px solid #d0d9e0;
+ margin:0 0 6px -8px;
+ padding:7px 5px;
+}
+ul.blockList ul.blockList ul.blockList li.blockList h3 {
+ background-color:#dee3e9;
+ border:1px solid #d0d9e0;
+ margin:0 0 6px -8px;
+ padding:7px 5px;
+}
+ul.blockList ul.blockList li.blockList h3 {
+ padding:0;
+ margin:15px 0;
+}
+ul.blockList li.blockList h2 {
+ padding:0px 0 20px 0;
+}
+/*
+Page layout container styles
+*/
+.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer {
+ clear:both;
+ padding:10px 20px;
+ position:relative;
+}
+.indexContainer {
+ margin:10px;
+ position:relative;
+ font-size:12px;
+}
+.indexContainer h2 {
+ font-size:13px;
+ padding:0 0 3px 0;
+}
+.indexContainer ul {
+ margin:0;
+ padding:0;
+}
+.indexContainer ul li {
+ list-style:none;
+ padding-top:2px;
+}
+.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt {
+ font-size:12px;
+ font-weight:bold;
+ margin:10px 0 0 0;
+ color:#4E4E4E;
+}
+.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd {
+ margin:5px 0 10px 0px;
+ font-size:14px;
+ font-family:'DejaVu Sans Mono',monospace;
+}
+.serializedFormContainer dl.nameValue dt {
+ margin-left:1px;
+ font-size:1.1em;
+ display:inline;
+ font-weight:bold;
+}
+.serializedFormContainer dl.nameValue dd {
+ margin:0 0 0 1px;
+ font-size:1.1em;
+ display:inline;
+}
+/*
+List styles
+*/
+ul.horizontal li {
+ display:inline;
+ font-size:0.9em;
+}
+ul.inheritance {
+ margin:0;
+ padding:0;
+}
+ul.inheritance li {
+ display:inline;
+ list-style:none;
+}
+ul.inheritance li ul.inheritance {
+ margin-left:15px;
+ padding-left:15px;
+ padding-top:1px;
+}
+ul.blockList, ul.blockListLast {
+ margin:10px 0 10px 0;
+ padding:0;
+}
+ul.blockList li.blockList, ul.blockListLast li.blockList {
+ list-style:none;
+ margin-bottom:15px;
+ line-height:1.4;
+}
+ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList {
+ padding:0px 20px 5px 10px;
+ border:1px solid #ededed;
+ background-color:#f8f8f8;
+}
+ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList {
+ padding:0 0 5px 8px;
+ background-color:#ffffff;
+ border:none;
+}
+ul.blockList ul.blockList ul.blockList ul.blockList li.blockList {
+ margin-left:0;
+ padding-left:0;
+ padding-bottom:15px;
+ border:none;
+}
+ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
+ list-style:none;
+ border-bottom:none;
+ padding-bottom:0;
+}
+table tr td dl, table tr td dl dt, table tr td dl dd {
+ margin-top:0;
+ margin-bottom:1px;
+}
+/*
+Table styles
+*/
+.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary {
+ width:100%;
+ border-left:1px solid #EEE;
+ border-right:1px solid #EEE;
+ border-bottom:1px solid #EEE;
+}
+.overviewSummary, .memberSummary {
+ padding:0px;
+}
+.overviewSummary caption, .memberSummary caption, .typeSummary caption,
+.useSummary caption, .constantsSummary caption, .deprecatedSummary caption {
+ position:relative;
+ text-align:left;
+ background-repeat:no-repeat;
+ color:#253441;
+ font-weight:bold;
+ clear:none;
+ overflow:hidden;
+ padding:0px;
+ padding-top:10px;
+ padding-left:1px;
+ margin:0px;
+ white-space:pre;
+}
+.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link,
+.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link,
+.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover,
+.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover,
+.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active,
+.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active,
+.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited,
+.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited {
+ color:#FFFFFF;
+}
+.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span,
+.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span {
+ white-space:nowrap;
+ padding-top:5px;
+ padding-left:12px;
+ padding-right:12px;
+ padding-bottom:7px;
+ display:inline-block;
+ float:left;
+ background-color:#F8981D;
+ border: none;
+ height:16px;
+}
+.memberSummary caption span.activeTableTab span {
+ white-space:nowrap;
+ padding-top:5px;
+ padding-left:12px;
+ padding-right:12px;
+ margin-right:3px;
+ display:inline-block;
+ float:left;
+ background-color:#F8981D;
+ height:16px;
+}
+.memberSummary caption span.tableTab span {
+ white-space:nowrap;
+ padding-top:5px;
+ padding-left:12px;
+ padding-right:12px;
+ margin-right:3px;
+ display:inline-block;
+ float:left;
+ background-color:#4D7A97;
+ height:16px;
+}
+.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab {
+ padding-top:0px;
+ padding-left:0px;
+ padding-right:0px;
+ background-image:none;
+ float:none;
+ display:inline;
+}
+.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd,
+.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd {
+ display:none;
+ width:5px;
+ position:relative;
+ float:left;
+ background-color:#F8981D;
+}
+.memberSummary .activeTableTab .tabEnd {
+ display:none;
+ width:5px;
+ margin-right:3px;
+ position:relative;
+ float:left;
+ background-color:#F8981D;
+}
+.memberSummary .tableTab .tabEnd {
+ display:none;
+ width:5px;
+ margin-right:3px;
+ position:relative;
+ background-color:#4D7A97;
+ float:left;
+
+}
+.overviewSummary td, .memberSummary td, .typeSummary td,
+.useSummary td, .constantsSummary td, .deprecatedSummary td {
+ text-align:left;
+ padding:0px 0px 12px 10px;
+}
+th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th,
+td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{
+ vertical-align:top;
+ padding-right:0px;
+ padding-top:8px;
+ padding-bottom:3px;
+}
+th.colFirst, th.colLast, th.colOne, .constantsSummary th {
+ background:#dee3e9;
+ text-align:left;
+ padding:8px 3px 3px 7px;
+}
+td.colFirst, th.colFirst {
+ white-space:nowrap;
+ font-size:13px;
+}
+td.colLast, th.colLast {
+ font-size:13px;
+}
+td.colOne, th.colOne {
+ font-size:13px;
+}
+.overviewSummary td.colFirst, .overviewSummary th.colFirst,
+.useSummary td.colFirst, .useSummary th.colFirst,
+.overviewSummary td.colOne, .overviewSummary th.colOne,
+.memberSummary td.colFirst, .memberSummary th.colFirst,
+.memberSummary td.colOne, .memberSummary th.colOne,
+.typeSummary td.colFirst{
+ width:25%;
+ vertical-align:top;
+}
+td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover {
+ font-weight:bold;
+}
+.tableSubHeadingColor {
+ background-color:#EEEEFF;
+}
+.altColor {
+ background-color:#FFFFFF;
+}
+.rowColor {
+ background-color:#EEEEEF;
+}
+/*
+Content styles
+*/
+.description pre {
+ margin-top:0;
+}
+.deprecatedContent {
+ margin:0;
+ padding:10px 0;
+}
+.docSummary {
+ padding:0;
+}
+
+ul.blockList ul.blockList ul.blockList li.blockList h3 {
+ font-style:normal;
+}
+
+div.block {
+ font-size:14px;
+ font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
+}
+
+td.colLast div {
+ padding-top:0px;
+}
+
+
+td.colLast a {
+ padding-bottom:3px;
+}
+/*
+Formatting effect styles
+*/
+.sourceLineNo {
+ color:green;
+ padding:0 30px 0 0;
+}
+h1.hidden {
+ visibility:hidden;
+ overflow:hidden;
+ font-size:10px;
+}
+.block {
+ display:block;
+ margin:3px 10px 2px 0px;
+ color:#474747;
+}
+.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink,
+.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel,
+.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink {
+ font-weight:bold;
+}
+.deprecationComment, .emphasizedPhrase, .interfaceName {
+ font-style:italic;
+}
+
+div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase,
+div.block div.block span.interfaceName {
+ font-style:normal;
+}
+
+div.contentContainer ul.blockList li.blockList h2{
+ padding-bottom:0px;
+}
diff --git a/pom.xml b/pom.xml
index 21d55bf..c35e2ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,19 @@
4.0.0
coding-competition
1.0.0-SNAPSHOT
- jar
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+
+ jar
sf.codingcompetition2020
coding-competition
diff --git a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java
index 58267da..7bebce9 100644
--- a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java
+++ b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java
@@ -1,147 +1,287 @@
package sf.codingcompetition2020;
-import java.io.FileReader;
-import java.io.Reader;
+import com.fasterxml.jackson.databind.MappingIterator;
+import com.fasterxml.jackson.dataformat.csv.CsvMapper;
+import com.fasterxml.jackson.dataformat.csv.CsvParser;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.lang.reflect.InvocationTargetException;
+
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.MappingIterator;
-import com.fasterxml.jackson.databind.ObjectReader;
-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.utilities.Pair;
+/**
+ * This class processes CSV data related to Insurance policy data.
+ * @author Mudit Gupta
+ * @author Manoj Niverthi
+ * @version 1.2
+ */
public class CodingCompCsvUtil {
-
- /* #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) {
- }
+ /* #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.
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List readCsvFile(String filePath, Class classType) throws IOException {
+ List interpretedFile = new ArrayList<>();
-
- /* #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) {
+ File csvFile = new File(filePath);
+ CsvMapper mapper = new CsvMapper();
+ mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
+ MappingIterator it = mapper.readerFor(Object[].class).readValues(csvFile);
+ it.nextValue();
+ it.forEachRemaining(row -> {
+ try {
+ interpretedFile.add(classType.getConstructor(List.class).newInstance(Arrays.asList(row)));
+ } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ });
+ return interpretedFile;
+ }
- }
-
- /* #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) {
+ /* #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
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public int getAgentCountInArea(String filePath, String area) throws IOException {
+ return (int) readCsvFile(filePath, Agent.class).stream().filter(agent -> agent.getArea().equals(area)).count();
+ }
- }
-
-
- /* #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) {
-
- }
-
- /* #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.
- */
- public List getCustomersRetainedForYearsByPlcyCostAsc(String customerFilePath, short yearsOfService) {
+ /* #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
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List getAgentsInAreaThatSpeakLanguage(String filePath, String area,
+ String language) throws IOException {
+ return readCsvFile(filePath, Agent.class).stream()
+ .filter(agent -> agent.getArea().equals(area) && agent.getLanguage().equals(language))
+ .collect(Collectors.toList());
+ }
- }
-
- /* #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.
- */
- public List getLeadsForInsurance(String filePath) {
+ /* #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.
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public short countCustomersFromAreaThatUseAgent(Map csvFilePaths, String customerArea,
+ String agentFirstName, String agentLastName) throws IOException {
+ Agent desiredAgent = (Agent) readCsvFile(csvFilePaths.get("agentList"), Agent.class).stream()
+ .filter(agent -> agent.getFirstName().equals(agentFirstName) && agent.getLastName()
+ .equals(agentLastName)).toArray()[0];
+ return (short) readCsvFile(csvFilePaths.get("customerList"), Customer.class).stream()
+ .filter(customer -> customer.getArea()
+ .equals(customerArea) && customer.getAgentId() == desiredAgent.getAgentId()).count();
+ }
- }
+ /* #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.
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List getCustomersRetainedForYearsByPlcyCostAsc(String customerFilePath,
+ short yearsOfService) throws IOException {
+ return readCsvFile(customerFilePath, Customer.class).stream()
+ .filter(customer -> customer.getYearsOfService() == yearsOfService)
+ .sorted(Comparator.comparingInt(Customer::getTotalMonthlyPremium)).collect(Collectors.toList());
+ }
- /* #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.
- */
- public List getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope, int vendorRating) {
- }
+ /* #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.
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List getLeadsForInsurance(String filePath) throws IOException {
+ return readCsvFile(filePath, Customer.class).stream()
+ .filter(customer -> !customer.hasAutoPolicy() && !customer.hasHomePolicy() && !customer.hasRentersPolicy())
+ .collect(Collectors.toList());
+ }
- /* #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.
- */
- public List getUndisclosedDrivers(String filePath, int vehiclesInsured, int dependents) {
+ /* #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.
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope,
+ int vendorRating) throws IOException {
+ return readCsvFile(filePath, Vendor.class).stream()
+ .filter(vendor -> vendor.getArea().equals(area)
+ && vendor.getVendorRating() >= vendorRating && (!inScope || vendor.isInScope()))
+ .collect(Collectors.toList());
+ }
- }
+
+ /* #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.
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List getUndisclosedDrivers(String filePath, int vehiclesInsured, int dependents) throws IOException {
+ return readCsvFile(filePath, Customer.class).stream()
+ .filter(customer -> customer.getAge() >= 40 && customer.getAge() <= 50
+ && customer.getVehiclesInsured() > vehiclesInsured && customer.getDependents().size() <= dependents)
+ .collect(Collectors.toList());
+ }
/* #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.
+ * *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.
+ * @throws IOException -- If file is interpreted incorrectly
*/
- public int getAgentIdGivenRank(String filePath, int agentRank) {
-
+ public int getAgentIdGivenRank(String filePath, int agentRank) throws IOException {
+ List allCustomers = readCsvFile(filePath, Customer.class);
+ int numberOfAgents = Integer.MIN_VALUE;
+ for (Customer currentCustomer : allCustomers) {
+ numberOfAgents = Math.min(numberOfAgents, currentCustomer.getAgentId());
+ }
+ Map> agentRatingsMap = new HashMap<>();
+ for (Customer currentCustomer : allCustomers) {
+ int currentAgentId = currentCustomer.getAgentId();
+ int currentAgentRating = currentCustomer.getAgentRating();
+ if (agentRatingsMap.containsKey(currentAgentId)) {
+ List currentAgentList = agentRatingsMap.get(currentAgentId);
+ currentAgentList.set(0, currentAgentList.get(0) + 1);
+ currentAgentList.set(1, currentAgentList.get(1) + currentAgentRating);
+ agentRatingsMap.put(currentAgentId, currentAgentList);
+ } else {
+ List newAgentList = new ArrayList<>();
+ newAgentList.add(1);
+ newAgentList.add(currentAgentRating);
+ agentRatingsMap.put(currentAgentId, newAgentList);
+ }
+ }
+ List> agentAverageRatings = new ArrayList<>();
+ for (Map.Entry> entry : agentRatingsMap.entrySet()) {
+ Integer agentId = entry.getKey();
+ Integer numReviews = entry.getValue().get(0);
+ Integer totalRating = entry.getValue().get(1);
+ Double averageRating = (double)(totalRating) / numReviews;
+ agentAverageRatings.add(new Pair<>(agentId, averageRating));
+ }
+ Collections.sort(agentAverageRatings, (o1, o2) -> {
+ if (o1.getValue2() < o2.getValue2()) {
+ return 1;
+ } else if (o1.getValue2() > o2.getValue2()) {
+ return -1;
+ }
+ return 0;
+ });
+ return agentAverageRatings.get(agentRank - 1).getValue1();
}
-
- /* #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 .
- */
- public List getCustomersWithClaims(Map csvFilePaths, short monthsOpen) {
- }
+ /* #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 .
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List getCustomersWithClaims(Map csvFilePaths, short monthsOpen) throws IOException {
+ List customerIDsWithRecentClaim = readCsvFile(csvFilePaths.get("claimList"), Claim.class).stream()
+ .filter(claim -> claim.getMonthsOpen() <= monthsOpen).map(claim -> claim.getCustomerId())
+ .collect(Collectors.toList());
+ return readCsvFile(csvFilePaths.get("customerList"), Customer.class).stream()
+ .filter(customer -> customerIDsWithRecentClaim.contains(customer.getCustomerId()))
+ .collect(Collectors.toList());
+ }
+
+ /* Custom methods: 1
+ * getCustomersBasedOnNumberOfPolicies() -- Return a list of customers who have
+ * policies (inclusive).
+ * @param filePath -- Path to file being read in.
+ * @param numberOfPolicies -- Number of months a policy has been open.
+ * @return -- List of customers who have policies.
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List getCustomersBasedOnNumberOfPolicies(String filePath, int numberOfPolicies) throws IOException {
+ return readCsvFile(filePath, Customer.class).stream().filter(customer -> {
+ int policyCount = 0;
+ if (customer.hasAutoPolicy()) {
+ policyCount++;
+ }
+ if (customer.hasHomePolicy()) {
+ policyCount++;
+ }
+ if (customer.hasRentersPolicy()) {
+ policyCount++;
+ }
+ return policyCount == numberOfPolicies;
+ }).collect(Collectors.toList());
+ }
+ /* Custom methods #2
+ * getVendorsForCustomerBasedOnArea() -- Return a list of vendors that operate in the area of a given customer.
+ * @param csvFilePaths -- Paths to files being read in.
+ * @param customerFirstName -- last name of customer
+ * @param customerLastName -- first name of customer
+ * @return -- list of vendors that operate in the area of a given customer
+ * @throws IOException -- If file is interpreted incorrectly
+ */
+ public List getVendorsForCustomerBasedOnArea(Map csvFilePaths, String customerFirstName,
+ String customerLastName) throws IOException {
+ String desiredArea = readCsvFile(csvFilePaths.get("customerList"), Customer.class).stream()
+ .filter(customer -> customer.getFirstName().equals(customerFirstName) && customer.getLastName()
+ .equals(customerLastName)).iterator().next().getArea();
+ return readCsvFile(csvFilePaths.get("vendorList"), Vendor.class).stream()
+ .filter(vendor -> vendor.getArea().equals(desiredArea)).collect(Collectors.toList());
+ }
}
diff --git a/src/main/java/sf/codingcompetition2020/structures/Agent.java b/src/main/java/sf/codingcompetition2020/structures/Agent.java
index e2e6f93..c99fc65 100644
--- a/src/main/java/sf/codingcompetition2020/structures/Agent.java
+++ b/src/main/java/sf/codingcompetition2020/structures/Agent.java
@@ -1,11 +1,181 @@
package sf.codingcompetition2020.structures;
+import java.util.List;
+
public class Agent {
-
- private int agentId;
- private String area;
- private String language;
- private String firstName;
- private String lastName;
-
+
+ private int agentId;
+ private String area;
+ private String language;
+ private String firstName;
+ private String lastName;
+
+ /**
+ * Default Agent constructor
+ */
+ private 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;
+ }
+
+ /**
+ * constructor based on an entry in a CSV
+ * @param csvEntry
+ */
+ public Agent(List csvEntry) {
+ this(
+ Integer.parseInt(csvEntry.get(0)),
+ csvEntry.get(1),
+ csvEntry.get(2),
+ csvEntry.get(3),
+ csvEntry.get(4));
+ }
+
+ /**
+ * Builder constructor
+ * @param builder
+ */
+ public Agent(Builder builder) {
+ this(
+ builder.agentId,
+ builder.area,
+ builder.language,
+ builder.firstName,
+ builder.lastName);
+ }
+
+ /**
+ * Returns value of agentId
+ * @return
+ */
+ public int getAgentId() {
+ return agentId;
+ }
+
+ /**
+ * Sets new value of agentId
+ * @param
+ */
+ public void setAgentId(int agentId) {
+ this.agentId = agentId;
+ }
+
+ /**
+ * Returns value of area
+ * @return
+ */
+ public String getArea() {
+ return area;
+ }
+
+ /**
+ * Sets new value of area
+ * @param
+ */
+ public void setArea(String area) {
+ this.area = area;
+ }
+
+ /**
+ * Returns value of language
+ * @return
+ */
+ public String getLanguage() {
+ return language;
+ }
+
+ /**
+ * Sets new value of language
+ * @param
+ */
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ /**
+ * Returns value of firstName
+ * @return
+ */
+ public String getFirstName() {
+ return firstName;
+ }
+
+ /**
+ * Sets new value of firstName
+ * @param
+ */
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ /**
+ * Returns value of lastName
+ * @return
+ */
+ public String getLastName() {
+ return lastName;
+ }
+
+ /**
+ * Sets new value of lastName
+ * @param
+ */
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Override
+ public String toString() {
+ return "Agent{" +
+ "agentId=" + agentId +
+ ", area='" + area + '\'' +
+ ", language='" + language + '\'' +
+ ", firstName='" + firstName + '\'' +
+ ", lastName='" + lastName + '\'' +
+ '}';
+ }
+
+ public static class Builder {
+ private int agentId;
+ private String area;
+ private String language;
+ private String firstName;
+ private String lastName;
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public Builder agentId(int agentId) {
+ this.agentId = agentId;
+ return this;
+ }
+
+ public Builder area(String area) {
+ this.area = area;
+ return this;
+ }
+
+ public Builder language(String language) {
+ this.language = language;
+ return this;
+ }
+
+ public Builder firstName(String firstName) {
+ this.firstName = firstName;
+ return this;
+ }
+
+ public Builder lastName(String lastName) {
+ this.lastName = lastName;
+ return this;
+ }
+
+ public Agent build() {
+ return new Agent(this);
+ }
+ }
}
diff --git a/src/main/java/sf/codingcompetition2020/structures/Claim.java b/src/main/java/sf/codingcompetition2020/structures/Claim.java
index 581140a..216fed0 100644
--- a/src/main/java/sf/codingcompetition2020/structures/Claim.java
+++ b/src/main/java/sf/codingcompetition2020/structures/Claim.java
@@ -1,9 +1,155 @@
package sf.codingcompetition2020.structures;
+import java.util.List;
+
public class Claim {
- private int claimId;
- private int customerId;
- private boolean closed;
- private int monthsOpen;
-
+
+ private int claimId;
+ private int customerId;
+ private boolean closed;
+ private int monthsOpen;
+
+ /**
+ * Default Claim constructor
+ */
+ public Claim(int claimId, int customerId, boolean closed, int monthsOpen) {
+ this.claimId = claimId;
+ this.customerId = customerId;
+ this.closed = closed;
+ this.monthsOpen = monthsOpen;
+ }
+
+ /**
+ * constructor based on an entry in a CSV
+ * @param csvEntry
+ */
+ public Claim(List csvEntry) {
+ this(
+ Integer.parseInt(csvEntry.get(0)),
+ Integer.parseInt(csvEntry.get(1)),
+ Boolean.parseBoolean(csvEntry.get(2)),
+ Integer.parseInt(csvEntry.get(3)));
+ }
+
+ /**
+ * Builder constructor
+ * @param builder
+ */
+ public Claim(Builder builder) {
+ this(
+ builder.claimId,
+ builder.customerId,
+ builder.closed,
+ builder.monthsOpen);
+ }
+
+ /**
+ * Returns value of claimId
+ * @return
+ */
+ public int getClaimId() {
+ return claimId;
+ }
+
+ /**
+ * Sets new value of claimId
+ * @param
+ */
+ public void setClaimId(int claimId) {
+ this.claimId = claimId;
+ }
+
+ /**
+ * Returns value of customerId
+ * @return
+ */
+ public int getCustomerId() {
+ return customerId;
+ }
+
+ /**
+ * Sets new value of customerId
+ * @param
+ */
+ public void setCustomerId(int customerId) {
+ this.customerId = customerId;
+ }
+
+ /**
+ * Returns value of closed
+ * @return
+ */
+ public boolean isClosed() {
+ return closed;
+ }
+
+ /**
+ * Sets new value of closed
+ * @param
+ */
+ public void setClosed(boolean closed) {
+ this.closed = closed;
+ }
+
+ /**
+ * Returns value of monthsOpen
+ * @return
+ */
+ public int getMonthsOpen() {
+ return monthsOpen;
+ }
+
+ /**
+ * Sets new value of monthsOpen
+ * @param
+ */
+ public void setMonthsOpen(int monthsOpen) {
+ this.monthsOpen = monthsOpen;
+ }
+
+ @Override
+ public String toString() {
+ return "Claim{" +
+ "claimId=" + claimId +
+ ", customerId=" + customerId +
+ ", closed=" + closed +
+ ", monthsOpen=" + monthsOpen +
+ '}';
+ }
+
+ public static class Builder {
+ private int claimId;
+ private int customerId;
+ private boolean closed;
+ private int monthsOpen;
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public Builder claimId(int claimId) {
+ this.claimId = claimId;
+ return this;
+ }
+
+ public Builder customerId(int customerId) {
+ this.customerId = customerId;
+ return this;
+ }
+
+ public Builder closed(boolean closed) {
+ this.closed = closed;
+ return this;
+ }
+
+ public Builder monthsOpen(int monthsOpen) {
+ this.monthsOpen = monthsOpen;
+ return this;
+ }
+
+ public Claim build() {
+ return new Claim(this);
+ }
+ }
+
}
diff --git a/src/main/java/sf/codingcompetition2020/structures/Customer.java b/src/main/java/sf/codingcompetition2020/structures/Customer.java
index f151906..1258893 100644
--- a/src/main/java/sf/codingcompetition2020/structures/Customer.java
+++ b/src/main/java/sf/codingcompetition2020/structures/Customer.java
@@ -4,24 +4,456 @@
import java.util.List;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.DeserializationFeature;
public class Customer {
- private int customerId;
- private String firstName;
- private String lastName;
- private int age;
- private String area;
- private int agentId;
- private short agentRating;
- private String primaryLanguage;
- private List dependents;
- private boolean homePolicy;
- private boolean autoPolicy;
- private boolean rentersPolicy;
- private String totalMonthlyPremium;
- private short yearsOfService;
- private Integer vehiclesInsured;
+ private int customerId;
+ private String firstName;
+ private String lastName;
+ private int age;
+ private String area;
+ private int agentId;
+ private short agentRating;
+ private String primaryLanguage;
+ private List dependents;
+ private boolean homePolicy;
+ private boolean autoPolicy;
+ private boolean rentersPolicy;
+ private int totalMonthlyPremium;
+ private short yearsOfService;
+ private int vehiclesInsured;
+
+ /**
+ * Default Customer constructor
+ */
+ 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, int 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 = Integer.parseInt(totalMonthlyPremium.substring(1));
+ this.yearsOfService = yearsOfService;
+ this.vehiclesInsured = vehiclesInsured;
+ }
+
+ /**
+ * constructor based on an entry in a CSV
+ * @param csvEntry
+ */
+ public Customer(List csvEntry) throws JsonProcessingException {
+ this(
+ Integer.parseInt(csvEntry.get(0)),
+ csvEntry.get(1),
+ csvEntry.get(2),
+ Integer.parseInt(csvEntry.get(3)),
+ csvEntry.get(4),
+ Integer.parseInt(csvEntry.get(5)),
+ Short.parseShort(csvEntry.get(6)),
+ csvEntry.get(7),
+ csvEntry.get(8).isEmpty() ? new ArrayList<>() : new ObjectMapper().readValue(csvEntry.get(8), new TypeReference>(){}),
+ Boolean.parseBoolean(csvEntry.get(9)),
+ Boolean.parseBoolean(csvEntry.get(10)),
+ Boolean.parseBoolean(csvEntry.get(11)),
+ csvEntry.get(12),
+ Short.parseShort(csvEntry.get(13)),
+ Integer.parseInt(csvEntry.get(14))
+ );
+ }
+
+ /**
+ * Builder constructor
+ * @param builder
+ */
+ public Customer(Builder builder) {
+ this(
+ builder.customerId,
+ builder.firstName,
+ builder.lastName,
+ builder.age,
+ builder.area,
+ builder.agentId,
+ builder.agentRating,
+ builder.primaryLanguage,
+ builder.dependents,
+ builder.homePolicy,
+ builder.autoPolicy,
+ builder.rentersPolicy,
+ builder.totalMonthlyPremium,
+ builder.yearsOfService,
+ builder.vehiclesInsured);
+ }
+
+ /**
+ * Returns value of customerId
+ * @return
+ */
+ public int getCustomerId() {
+ return customerId;
+ }
+
+ /**
+ * Sets new value of customerId
+ * @param
+ */
+ public void setCustomerId(int customerId) {
+ this.customerId = customerId;
+ }
+
+ /**
+ * Returns value of firstName
+ * @return
+ */
+ public String getFirstName() {
+ return firstName;
+ }
+
+ /**
+ * Sets new value of firstName
+ * @param
+ */
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ /**
+ * Returns value of lastName
+ * @return
+ */
+ public String getLastName() {
+ return lastName;
+ }
+
+ /**
+ * Sets new value of lastName
+ * @param
+ */
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ /**
+ * Returns value of age
+ * @return
+ */
+ public int getAge() {
+ return age;
+ }
+
+ /**
+ * Sets new value of age
+ * @param
+ */
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ /**
+ * Returns value of area
+ * @return
+ */
+ public String getArea() {
+ return area;
+ }
+
+ /**
+ * Sets new value of area
+ * @param
+ */
+ public void setArea(String area) {
+ this.area = area;
+ }
+
+ /**
+ * Returns value of agentId
+ * @return
+ */
+ public int getAgentId() {
+ return agentId;
+ }
+
+ /**
+ * Sets new value of agentId
+ * @param
+ */
+ public void setAgentId(int agentId) {
+ this.agentId = agentId;
+ }
+
+ /**
+ * Returns value of agentRating
+ * @return
+ */
+ public short getAgentRating() {
+ return agentRating;
+ }
+
+ /**
+ * Sets new value of agentRating
+ * @param
+ */
+ public void setAgentRating(short agentRating) {
+ this.agentRating = agentRating;
+ }
+
+ /**
+ * Returns value of primaryLanguage
+ * @return
+ */
+ public String getPrimaryLanguage() {
+ return primaryLanguage;
+ }
+
+ /**
+ * Sets new value of primaryLanguage
+ * @param
+ */
+ public void setPrimaryLanguage(String primaryLanguage) {
+ this.primaryLanguage = primaryLanguage;
+ }
+
+ /**
+ * Returns value of dependents
+ * @return
+ */
+ public List getDependents() {
+ return dependents;
+ }
+
+ /**
+ * Sets new value of dependents
+ * @param
+ */
+ public void setDependents(List dependents) {
+ this.dependents = dependents;
+ }
+
+ /**
+ * Returns value of homePolicy
+ * @return
+ */
+ public boolean hasHomePolicy() {
+ return homePolicy;
+ }
+
+ /**
+ * Sets new value of homePolicy
+ * @param
+ */
+ public void setHomePolicy(boolean homePolicy) {
+ this.homePolicy = homePolicy;
+ }
+
+ /**
+ * Returns value of autoPolicy
+ * @return
+ */
+ public boolean hasAutoPolicy() {
+ return autoPolicy;
+ }
+
+ /**
+ * Sets new value of autoPolicy
+ * @param
+ */
+ public void setAutoPolicy(boolean autoPolicy) {
+ this.autoPolicy = autoPolicy;
+ }
+
+ /**
+ * Returns value of rentersPolicy
+ * @return
+ */
+ public boolean hasRentersPolicy() {
+ return rentersPolicy;
+ }
+
+ /**
+ * Sets new value of rentersPolicy
+ * @param
+ */
+ public void setRentersPolicy(boolean rentersPolicy) {
+ this.rentersPolicy = rentersPolicy;
+ }
+
+ /**
+ * Returns value of totalMonthlyPremium
+ * @return
+ */
+ public int getTotalMonthlyPremium() {
+ return totalMonthlyPremium;
+ }
+
+ /**
+ * Sets new value of totalMonthlyPremium
+ * @param
+ */
+ public void setTotalMonthlyPremium(String totalMonthlyPremium) {
+ this.totalMonthlyPremium = Integer.parseInt(totalMonthlyPremium.substring(1));
+ }
+
+ /**
+ * Returns value of yearsOfService
+ * @return
+ */
+ public short getYearsOfService() {
+ return yearsOfService;
+ }
+
+ /**
+ * Sets new value of yearsOfService
+ * @param
+ */
+ public void setYearsOfService(short yearsOfService) {
+ this.yearsOfService = yearsOfService;
+ }
+
+ /**
+ * Returns value of vehiclesInsured
+ * @return
+ */
+ public int getVehiclesInsured() {
+ return vehiclesInsured;
+ }
+
+ /**
+ * Sets new value of vehiclesInsured
+ * @param
+ */
+ public void setVehiclesInsured(int vehiclesInsured) {
+ this.vehiclesInsured = vehiclesInsured;
+ }
+
+ @Override
+ public String toString() {
+ return "Customer{" +
+ "customerId=" + customerId +
+ ", firstName='" + firstName + '\'' +
+ ", lastName='" + lastName + '\'' +
+ ", age=" + age +
+ ", area='" + area + '\'' +
+ ", agentId=" + agentId +
+ ", agentRating=" + agentRating +
+ ", primaryLanguage='" + primaryLanguage + '\'' +
+ ", dependents=" + dependents +
+ ", homePolicy=" + homePolicy +
+ ", autoPolicy=" + autoPolicy +
+ ", rentersPolicy=" + rentersPolicy +
+ ", totalMonthlyPremium=" + totalMonthlyPremium +
+ ", yearsOfService=" + yearsOfService +
+ ", vehiclesInsured=" + vehiclesInsured +
+ '}';
+ }
+
+ public static class Builder {
+ private int customerId;
+ private String firstName;
+ private String lastName;
+ private int age;
+ private String area;
+ private int agentId;
+ private short agentRating;
+ private String primaryLanguage;
+ private List dependents;
+ private boolean homePolicy;
+ private boolean autoPolicy;
+ private boolean rentersPolicy;
+ private String totalMonthlyPremium;
+ private short yearsOfService;
+ private int vehiclesInsured;
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public Builder customerId(int customerId) {
+ this.customerId = customerId;
+ return this;
+ }
+
+ public Builder firstName(String firstName) {
+ this.firstName = firstName;
+ return this;
+ }
+
+ public Builder lastName(String lastName) {
+ this.lastName = lastName;
+ return this;
+ }
+
+ public Builder age(int age) {
+ this.age = age;
+ return this;
+ }
+
+ public Builder area(String area) {
+ this.area = area;
+ return this;
+ }
+
+ public Builder agentId(int agentId) {
+ this.agentId = agentId;
+ return this;
+ }
+
+ public Builder agentRating(short agentRating) {
+ this.agentRating = agentRating;
+ return this;
+ }
+
+ public Builder primaryLanguage(String primaryLanguage) {
+ this.primaryLanguage = primaryLanguage;
+ return this;
+ }
+
+ public Builder dependents(List dependents) {
+ this.dependents = dependents;
+ return this;
+ }
+
+ public Builder homePolicy(boolean homePolicy) {
+ this.homePolicy = homePolicy;
+ return this;
+ }
+
+ public Builder autoPolicy(boolean autoPolicy) {
+ this.autoPolicy = autoPolicy;
+ return this;
+ }
+
+ public Builder rentersPolicy(boolean rentersPolicy) {
+ this.rentersPolicy = rentersPolicy;
+ return this;
+ }
+
+ public Builder totalMonthlyPremium(String totalMonthlyPremium) {
+ this.totalMonthlyPremium = totalMonthlyPremium;
+ return this;
+ }
+
+ public Builder yearsOfService(short yearsOfService) {
+ this.yearsOfService = yearsOfService;
+ return this;
+ }
+
+ public Builder vehiclesInsured(int vehiclesInsured) {
+ this.vehiclesInsured = vehiclesInsured;
+ return this;
+ }
+
+ public Customer build() {
+ return new Customer(this);
+ }
+ }
}
diff --git a/src/main/java/sf/codingcompetition2020/structures/Dependent.java b/src/main/java/sf/codingcompetition2020/structures/Dependent.java
index d4deb1a..df3c6d8 100644
--- a/src/main/java/sf/codingcompetition2020/structures/Dependent.java
+++ b/src/main/java/sf/codingcompetition2020/structures/Dependent.java
@@ -1,7 +1,103 @@
package sf.codingcompetition2020.structures;
+import java.util.List;
+
public class Dependent {
- private String firstName;
- private String lastName;
+ private String firstName;
+ private String lastName;
+
+ /**
+ *
+ */
+ public Dependent() {
+ super();
+ }
+ /**
+ * constructor based on an entry in a CSV
+ * @param csvEntry
+ */
+ public Dependent(List csvEntry) {
+ this(
+ csvEntry.get(0),
+ csvEntry.get(1)
+ );
+ }
+ /**
+ * Default Dependent constructor
+ */
+ public Dependent(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ /**
+ * Builder constructor
+ * @param builder
+ */
+ public Dependent(Builder builder) {
+ this(builder.firstName, builder.lastName);
+ }
+
+ /**
+ * Returns value of firstName
+ * @return
+ */
+ public String getFirstName() {
+ return firstName;
+ }
+
+ /**
+ * Sets new value of firstName
+ * @param
+ */
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ /**
+ * Returns value of lastName
+ * @return
+ */
+ public String getLastName() {
+ return lastName;
+ }
+
+ /**
+ * Sets new value of lastName
+ * @param
+ */
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Override
+ public String toString() {
+ return "Dependent{" +
+ "firstName='" + firstName + '\'' +
+ ", lastName='" + lastName + '\'' +
+ '}';
+ }
+
+ public static class Builder {
+ private String firstName;
+ private String lastName;
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public Builder firstName(String firstName) {
+ this.firstName = firstName;
+ return this;
+ }
+
+ public Builder lastName(String lastName) {
+ this.lastName = lastName;
+ return this;
+ }
+ public Dependent build() {
+ return new Dependent(this);
+ }
+ }
}
diff --git a/src/main/java/sf/codingcompetition2020/structures/Vendor.java b/src/main/java/sf/codingcompetition2020/structures/Vendor.java
index 6b6fb76..4ac28bb 100644
--- a/src/main/java/sf/codingcompetition2020/structures/Vendor.java
+++ b/src/main/java/sf/codingcompetition2020/structures/Vendor.java
@@ -1,9 +1,153 @@
package sf.codingcompetition2020.structures;
+import java.util.List;
+
public class Vendor {
- private int vendorId;
- private String area;
- private int vendorRating;
- private boolean inScope;
-
+ private int vendorId;
+ private String area;
+ private int vendorRating;
+ private boolean inScope;
+
+ /**
+ * Default Vendor constructor
+ */
+ public Vendor(int vendorId, String area, int vendorRating, boolean inScope) {
+ this.vendorId = vendorId;
+ this.area = area;
+ this.vendorRating = vendorRating;
+ this.inScope = inScope;
+ }
+
+ /**
+ * constructor based on an entry in a CSV
+ * @param csvEntry
+ */
+ public Vendor(List csvEntry) {
+ this(
+ Integer.parseInt(csvEntry.get(0)),
+ csvEntry.get(1),
+ Integer.parseInt(csvEntry.get(2)),
+ Boolean.parseBoolean(csvEntry.get(3)));
+ }
+
+ /**
+ * Builder constructor
+ * @param builder
+ */
+ public Vendor(Builder builder) {
+ this(
+ builder.vendorId,
+ builder.area,
+ builder.vendorRating,
+ builder.inScope);
+ }
+
+ /**
+ * Returns value of vendorId
+ * @return
+ */
+ public int getVendorId() {
+ return vendorId;
+ }
+
+ /**
+ * Sets new value of vendorId
+ * @param
+ */
+ public void setVendorId(int vendorId) {
+ this.vendorId = vendorId;
+ }
+
+ /**
+ * Returns value of area
+ * @return
+ */
+ public String getArea() {
+ return area;
+ }
+
+ /**
+ * Sets new value of area
+ * @param
+ */
+ public void setArea(String area) {
+ this.area = area;
+ }
+
+ /**
+ * Returns value of vendorRating
+ * @return
+ */
+ public int getVendorRating() {
+ return vendorRating;
+ }
+
+ /**
+ * Sets new value of vendorRating
+ * @param
+ */
+ public void setVendorRating(int vendorRating) {
+ this.vendorRating = vendorRating;
+ }
+
+ /**
+ * Returns value of inScope
+ * @return
+ */
+ public boolean isInScope() {
+ return inScope;
+ }
+
+ /**
+ * Sets new value of inScope
+ * @param
+ */
+ public void setInScope(boolean inScope) {
+ this.inScope = inScope;
+ }
+
+ @Override
+ public String toString() {
+ return "Vendor{" +
+ "vendorId=" + vendorId +
+ ", area='" + area + '\'' +
+ ", vendorRating=" + vendorRating +
+ ", inScope=" + inScope +
+ '}';
+ }
+
+ public static class Builder {
+ private int vendorId;
+ private String area;
+ private int vendorRating;
+ private boolean inScope;
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public Builder vendorId(int vendorId) {
+ this.vendorId = vendorId;
+ return this;
+ }
+
+ public Builder area(String area) {
+ this.area = area;
+ return this;
+ }
+
+ public Builder vendorRating(int vendorRating) {
+ this.vendorRating = vendorRating;
+ return this;
+ }
+
+ public Builder inScope(boolean inScope) {
+ this.inScope = inScope;
+ return this;
+ }
+
+ public Vendor build() {
+ return new Vendor(this);
+ }
+ }
}
diff --git a/src/main/java/sf/codingcompetition2020/utilities/Pair.java b/src/main/java/sf/codingcompetition2020/utilities/Pair.java
new file mode 100644
index 0000000..0ecef22
--- /dev/null
+++ b/src/main/java/sf/codingcompetition2020/utilities/Pair.java
@@ -0,0 +1,36 @@
+package sf.codingcompetition2020.utilities;
+
+public class Pair {
+
+ private T value1;
+ private V value2;
+
+ public Pair(T value1, V value2) {
+ this.value1 = value1;
+ this.value2 = value2;
+ }
+
+ public T getValue1() {
+ return value1;
+ }
+
+ public void setValue1(T value1) {
+ this.value1 = value1;
+ }
+
+ public V getValue2() {
+ return value2;
+ }
+
+ public void setValue2(V value2) {
+ this.value2 = value2;
+ }
+
+ @Override
+ public String toString() {
+ return "Pair{" +
+ "value1=" + value1 +
+ ", value2=" + value2 +
+ '}';
+ }
+}
diff --git a/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java b/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java
index c29959f..eefabcf 100644
--- a/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java
+++ b/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java
@@ -1,7 +1,9 @@
package sf.codingcompetition2020;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -11,6 +13,7 @@
import sf.codingcompetition2020.structures.Agent;
import sf.codingcompetition2020.structures.Claim;
import sf.codingcompetition2020.structures.Customer;
+import sf.codingcompetition2020.structures.Vendor;
public class CodingCompCsvUtilTest{
@@ -21,13 +24,14 @@ public class CodingCompCsvUtilTest{
private final String agentList = "agentList";
private final String claimList = "claimList";
private final String customerList = "customerList";
+ private final String vendorList = "vendorList";
CodingCompCsvUtil codingCompCsVUtil = new CodingCompCsvUtil();
//#1
@Test
- public void test1() {
+ public void test1() throws IOException {
assertEquals("Giacopo",((Agent)codingCompCsVUtil.readCsvFile(agentFilePath, Agent.class).get(1)).getFirstName());
assertEquals(424, ((Claim)codingCompCsVUtil.readCsvFile(claimFilePath, Claim.class).get(423)).getClaimId());
assertEquals("Lorin", ((Customer)codingCompCsVUtil.readCsvFile(customerFilePath, Customer.class).get(499)).getFirstName());
@@ -35,14 +39,14 @@ public void test1() {
//#2
@Test
- public void getAgentCountInArea() {
+ public void getAgentCountInArea() throws IOException {
assertEquals(247,codingCompCsVUtil.getAgentCountInArea(agentFilePath, "area-4"));
assertEquals(55,codingCompCsVUtil.getAgentCountInArea(agentFilePath, "area-2"));
}
//#3
@Test
- public void getAgentsInAreaThatSpeakLanguage() {
+ public void getAgentsInAreaThatSpeakLanguage() throws IOException {
List agentList = codingCompCsVUtil.getAgentsInAreaThatSpeakLanguage(agentFilePath, "area-3", "English");
assertEquals(2, agentList.size());
assertEquals(49, agentList.get(0).getAgentId());
@@ -55,7 +59,7 @@ public void getAgentsInAreaThatSpeakLanguage() {
//#4
@Test
- public void countCustomersFromCitythatUseAgent() {
+ public void countCustomersFromCitythatUseAgent() throws IOException {
Map csvFilePaths = new HashMap<>();
csvFilePaths.put(agentList, agentFilePath);
@@ -67,27 +71,27 @@ public void countCustomersFromCitythatUseAgent() {
//#5
@Test
- public void getCustomersRetainedForYearsByPlcyCostAsc() {
+ public void getCustomersRetainedForYearsByPlcyCostAsc() throws IOException {
List customerList = codingCompCsVUtil.getCustomersRetainedForYearsByPlcyCostAsc(customerFilePath, Short.valueOf("5"));
assertEquals(15,customerList.size());
assertEquals(215,customerList.get(0).getCustomerId());
assertEquals(5,customerList.get(2).getYearsOfService());
- assertEquals("$388",customerList.get(3).getTotalMonthlyPremium());
+ assertEquals(388,customerList.get(3).getTotalMonthlyPremium());
assertEquals("Janka",customerList.get(4).getFirstName());
assertEquals("Tesoe",customerList.get(5).getLastName());
- assertEquals("$888",customerList.get(14).getTotalMonthlyPremium());
+ assertEquals(888,customerList.get(14).getTotalMonthlyPremium());
}
//#6
@Test
- public void getLeadsForInsurance() {
+ public void getLeadsForInsurance() throws IOException {
assertEquals(82, codingCompCsVUtil.getLeadsForInsurance(customerFilePath).size());
}
//#7
@Test
- public void getVendorsWithGivenRatingThatAreInScope() {
+ public void getVendorsWithGivenRatingThatAreInScope() throws IOException {
assertEquals(11, codingCompCsVUtil.getVendorsWithGivenRatingThatAreInScope(vendorFilePath, "area-5", true, 4).size());
assertEquals(2, codingCompCsVUtil.getVendorsWithGivenRatingThatAreInScope(vendorFilePath, "area-2", true, 2).size());
assertEquals(12, codingCompCsVUtil.getVendorsWithGivenRatingThatAreInScope(vendorFilePath, "area-3", false, 3).size());
@@ -95,14 +99,14 @@ public void getVendorsWithGivenRatingThatAreInScope() {
//#8
@Test
- public void getCustomersRetainedForYearsByPlcyCostAsc2() {
+ public void getCustomersRetainedForYearsByPlcyCostAsc2() throws IOException {
assertEquals(15,codingCompCsVUtil.getUndisclosedDrivers(customerFilePath,2,2).size());
assertEquals(14,codingCompCsVUtil.getUndisclosedDrivers(customerFilePath,3,3).size());
}
//#9
@Test
- public void getAgentIdGivenRank() {
+ public void getAgentIdGivenRank() throws IOException {
assertEquals(3,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 1));
assertEquals(12,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 4));
assertEquals(14,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 20));
@@ -110,7 +114,7 @@ public void getAgentIdGivenRank() {
//#10
@Test
- public void getCountCustomersWithClaims() {
+ public void getCountCustomersWithClaims() throws IOException {
Map csvFilePaths = new HashMap<>();
csvFilePaths.put(customerList, customerFilePath);
@@ -118,7 +122,27 @@ public void getCountCustomersWithClaims() {
assertEquals(81,codingCompCsVUtil.getCustomersWithClaims(csvFilePaths, Short.valueOf("1")).size());
assertEquals(312,codingCompCsVUtil.getCustomersWithClaims(csvFilePaths, Short.valueOf("6")).size());
- }
+ }
+ //#Custom 1
+ @Test
+ public void getCustomersBasedOnNumberOfPolicies() throws IOException {
+ assertEquals(195, codingCompCsVUtil.getCustomersBasedOnNumberOfPolicies(customerFilePath, Integer.valueOf("1")).size());
+ assertEquals(40, codingCompCsVUtil.getCustomersBasedOnNumberOfPolicies(customerFilePath, Integer.valueOf("3")).size());
+ }
+
+ @Test
+ public void getVendorsForCustomerBasedOnArea() throws IOException {
+ Map csvFilePaths = new HashMap<>();
+ csvFilePaths.put(customerList, customerFilePath);
+ csvFilePaths.put(vendorList, vendorFilePath);
+ List result = codingCompCsVUtil.getVendorsForCustomerBasedOnArea(csvFilePaths, "Alexine", "Spinella");
+
+ assertEquals(52, result.size());
+ assertEquals(1, result.get(0).getVendorId());
+ assertTrue(result.get(0).isInScope());
+ assertEquals("area-5", result.get(1).getArea());
+ assertEquals(5, result.get(1).getVendorRating());
+ }
}
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.class b/target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class
deleted file mode 100644
index 00daba9..0000000
Binary files a/target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class and /dev/null differ
diff --git a/target/classes/sf/codingcompetition2020/structures/Agent.class b/target/classes/sf/codingcompetition2020/structures/Agent.class
deleted file mode 100644
index 26bf31f..0000000
Binary files a/target/classes/sf/codingcompetition2020/structures/Agent.class and /dev/null differ
diff --git a/target/classes/sf/codingcompetition2020/structures/Claim.class b/target/classes/sf/codingcompetition2020/structures/Claim.class
deleted file mode 100644
index 1ce796d..0000000
Binary files a/target/classes/sf/codingcompetition2020/structures/Claim.class and /dev/null differ
diff --git a/target/classes/sf/codingcompetition2020/structures/Customer.class b/target/classes/sf/codingcompetition2020/structures/Customer.class
deleted file mode 100644
index 844ea29..0000000
Binary files a/target/classes/sf/codingcompetition2020/structures/Customer.class and /dev/null differ
diff --git a/target/classes/sf/codingcompetition2020/structures/Dependent.class b/target/classes/sf/codingcompetition2020/structures/Dependent.class
deleted file mode 100644
index 3ee505f..0000000
Binary files a/target/classes/sf/codingcompetition2020/structures/Dependent.class and /dev/null differ
diff --git a/target/classes/sf/codingcompetition2020/structures/Vendor.class b/target/classes/sf/codingcompetition2020/structures/Vendor.class
deleted file mode 100644
index fdbca9b..0000000
Binary files a/target/classes/sf/codingcompetition2020/structures/Vendor.class and /dev/null differ
diff --git a/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class b/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class
deleted file mode 100644
index 765ac60..0000000
Binary files a/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class and /dev/null differ