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

2020-StateFarm-Comp #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions feedback.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Your team (name of each individual participating):
Your team: Chris Moore, Conley Price
How many JUnits were you able to get to pass?
4

Document and describe any enhancements included to help the judges properly grade your submission.
Step 1:
Step 2:
None


Feedback for the coding competition? Things you would like to see in future events?
None
271 changes: 219 additions & 52 deletions src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package sf.codingcompetition2020;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
Expand All @@ -22,126 +27,288 @@
import sf.codingcompetition2020.structures.Vendor;

public class CodingCompCsvUtil {

/* #1
* readCsvFile() -- Read in a CSV File and return a list of entries in that file.

/*
* #1 readCsvFile() -- Read in a CSV File and return a list of entries in that
* file.
*
* @param filePath -- Path to file being read in.
*
* @param classType -- Class of entries being read in.
*
* @return -- List of entries being returned.
*/
public <T> List<T> readCsvFile(String filePath, Class<T> classType) {
List<T> temp = new ArrayList<T>();

try {
Scanner scan = new Scanner(new File(filePath));
String line = "";

while (scan.hasNextLine()) {
line = scan.nextLine();
String[] lineList = line.split(",");
T c = classType.cast(new Agent(lineList));
if (classType == Agent.class) {
temp.add(classType.cast(new Agent(lineList)));
} else if (classType == Claim.class) {
temp.add(classType.cast(new Claim(lineList)));
} else if (classType == Vendor.class) {
temp.add(classType.cast(new Vendor(lineList)));
} else if (classType == Customer.class) {
temp.add(classType.cast(new Customer(createCustomerList(lineList))));
}
}

} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}

private String[] createCustomerList(String[] list) {
String[] out = new String[15];
for (int i = 0; i < 8; i++) {
out[i] = list[i];
}
StringBuffer sb = new StringBuffer();
for (int i = 8; i < list.length - 6; i++) {
sb.append(list[i]);
}
out[8] = sb.toString();
for (int i = 0; i < 6; i++) {
out[14 - i] = list[list.length - 1 - i];
}
return out;
}


/* #2
* getAgentCountInArea() -- Return the number of agents in a given area.
/*
* #2 getAgentCountInArea() -- Return the number of agents in a given area.
*
* @param filePath -- Path to file being read in.
*
* @param area -- The area from which the agents should be counted.
*
* @return -- The number of agents in a given area
*/
public int getAgentCountInArea(String filePath,String area) {
public int getAgentCountInArea(String filePath, String area) {

try {
Scanner scan = new Scanner(new File(filePath));
scan.nextLine();
int count = 0;
while (scan.hasNextLine()) {
String areaTemp = scan.nextLine().split(",")[1];
if (areaTemp.equals(area)) {
count++;
}
}
return count;
} catch (FileNotFoundException e) {
return (Integer) null;
}

}


/* #3
* getAgentsInAreaThatSpeakLanguage() -- Return a list of agents from a given area, that speak a certain language.
/*
* #3 getAgentsInAreaThatSpeakLanguage() -- Return a list of agents from a given
* area, that speak a certain language.
*
* @param filePath -- Path to file being read in.
*
* @param area -- The area from which the agents should be counted.
*
* @param language -- The language spoken by the agent(s).
*
* @return -- The number of agents in a given area
*/
public List<Agent> getAgentsInAreaThatSpeakLanguage(String filePath, String area, String language) {
List<Agent> result = new ArrayList<Agent>();

try {
Scanner scan = new Scanner(new File(filePath));
scan.nextLine();
int count = 0;
while (scan.hasNextLine()) {
String[] areaTemp = scan.nextLine().split(",");
if (areaTemp[1].equals(area) && areaTemp[2].equals(language)) {
Agent temp = new Agent(areaTemp);
result.add(temp);
}
}
return result;
} catch (FileNotFoundException e) {
return null;
}

}


/* #4
* countCustomersFromAreaThatUseAgent() -- Return the number of individuals from an area that use a certain agent.

/*
* #4 countCustomersFromAreaThatUseAgent() -- Return the number of individuals
* from an area that use a certain agent.
*
* @param filePath -- Path to file being read in.
*
* @param customerArea -- The area from which the customers should be counted.
*
* @param agentFirstName -- First name of agent.
*
* @param agentLastName -- Last name of agent.
*
* @return -- The number of customers that use a certain agent in a given area.
*/
public short countCustomersFromAreaThatUseAgent(Map<String,String> csvFilePaths, String customerArea, String agentFirstName, String agentLastName) {

public short countCustomersFromAreaThatUseAgent(Map<String, String> csvFilePaths, String customerArea,
String agentFirstName, String agentLastName) {
return -1;
}


/* #5
* getCustomersRetainedForYearsByPlcyCostAsc() -- Return a list of customers retained for a given number of years, in ascending order of their policy cost.
/*
* #5 getCustomersRetainedForYearsByPlcyCostAsc() -- Return a list of customers
* retained for a given number of years, in ascending order of their policy
* cost.
*
* @param filePath -- Path to file being read in.
*
* @param yearsOfServeice -- Number of years the person has been a customer.
* @return -- List of customers retained for a given number of years, in ascending order of policy cost.
*
* @return -- List of customers retained for a given number of years, in
* ascending order of policy cost.
*/
public List<Customer> getCustomersRetainedForYearsByPlcyCostAsc(String customerFilePath, short yearsOfService) {
List<Customer> result = new ArrayList<Customer>();

try {
Scanner scan = new Scanner(new File(customerFilePath));
scan.nextLine();

while (scan.hasNextLine()) {
String[] list = scan.nextLine().split(",");
if (list[list.length - 2].equals(yearsOfService + "")) {
for (String string : createCustomerList(list)) {
System.out.println(string);
}
System.out.println("\n\n");
Customer temp = new Customer(createCustomerList(list));
result.add(temp);
}
}
Collections.sort(result, new customerCostCompare());
return result;
} catch (FileNotFoundException e) {
return null;
}
}


/* #6
* getLeadsForInsurance() -- Return a list of individuals who’ve made an inquiry for a policy but have not signed up.
* *HINT* -- Look for customers that currently have no policies with the insurance company.
/*
* #6 getLeadsForInsurance() -- Return a list of individuals who’ve made an
* inquiry for a policy but have not signed up. *HINT* -- Look for customers
* that currently have no policies with the insurance company.
*
* @param filePath -- Path to file being read in.
* @return -- List of customers who’ve made an inquiry for a policy but have not signed up.
*
* @return -- List of customers who’ve made an inquiry for a policy but have
* not signed up.
*/
public List<Customer> getLeadsForInsurance(String filePath) {
List<Customer> result = new ArrayList<Customer>();

}
try {
Scanner scan = new Scanner(new File(filePath));
scan.nextLine();

while (scan.hasNextLine()) {
String[] temp = scan.nextLine().split(",");
if (temp.length > 4 && temp[temp.length - 4].equals("false") && temp[temp.length - 5].equals("false")
&& temp[temp.length - 6].equals("false")) {
Customer c = new Customer(createCustomerList(temp));
result.add(c);
}
}
} catch (FileNotFoundException e) {
return null;
}
return result;
}

/* #7
* getVendorsWithGivenRatingThatAreInScope() -- Return a list of vendors within an area and include options to narrow it down by:
a. Vendor rating
b. Whether that vendor is in scope of the insurance (if inScope == false, return all vendors in OR out of scope, if inScope == true, return ONLY vendors in scope)
/*
* #7 getVendorsWithGivenRatingThatAreInScope() -- Return a list of vendors
* within an area and include options to narrow it down by: a. Vendor rating b.
* Whether that vendor is in scope of the insurance (if inScope == false, return
* all vendors in OR out of scope, if inScope == true, return ONLY vendors in
* scope)
*
* @param filePath -- Path to file being read in.
*
* @param area -- Area of the vendor.
*
* @param inScope -- Whether or not the vendor is in scope of the insurance.
*
* @param vendorRating -- The rating of the vendor.
* @return -- List of vendors within a given area, filtered by scope and vendor rating.
*
* @return -- List of vendors within a given area, filtered by scope and vendor
* rating.
*/
public List<Vendor> getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope, int vendorRating) {
public List<Vendor> getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope,
int vendorRating) {

return null;
}


/* #8
* getUndisclosedDrivers() -- Return a list of customers between the age of 40 and 50 years (inclusive), who have:
a. More than X cars
b. less than or equal to X number of dependents.
/*
* #8 getUndisclosedDrivers() -- Return a list of customers between the age of
* 40 and 50 years (inclusive), who have: a. More than X cars b. less than or
* equal to X number of dependents.
*
* @param filePath -- Path to file being read in.
*
* @param vehiclesInsured -- The number of vehicles insured.
*
* @param dependents -- The number of dependents on the insurance policy.
* @return -- List of customers filtered by age, number of vehicles insured and the number of dependents.
*
* @return -- List of customers filtered by age, number of vehicles insured and
* the number of dependents.
*/
public List<Customer> getUndisclosedDrivers(String filePath, int vehiclesInsured, int dependents) {

}

return null;
}

/* #9
* getAgentIdGivenRank() -- Return the agent with the given rank based on average customer satisfaction rating.
* *HINT* -- Rating is calculated by taking all the agent rating by customers (1-5 scale) and dividing by the total number
* of reviews for the agent.
/*
* #9 getAgentIdGivenRank() -- Return the agent with the given rank based on
* average customer satisfaction rating. *HINT* -- Rating is calculated by
* taking all the agent rating by customers (1-5 scale) and dividing by the
* total number of reviews for the agent.
*
* @param filePath -- Path to file being read in.
*
* @param agentRank -- The rank of the agent being requested.
*
* @return -- Agent ID of agent with the given rank.
*/
public int getAgentIdGivenRank(String filePath, int agentRank) {
}
return -1;
}


/* #10
* getCustomersWithClaims() -- Return a list of customers who’ve filed a claim within the last <numberOfMonths> (inclusive).
/*
* #10 getCustomersWithClaims() -- Return a list of customers who’ve filed a
* claim within the last <numberOfMonths> (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 <numberOfMonths>.
*
* @return -- List of customers who’ve filed a claim within the last
* <numberOfMonths>.
*/
public List<Customer> getCustomersWithClaims(Map<String,String> csvFilePaths, short monthsOpen) {
public List<Customer> getCustomersWithClaims(Map<String, String> csvFilePaths, short monthsOpen) {

return null;
}

}
private class customerCostCompare implements Comparator<Customer> {
public int compare(Customer o1, Customer o2) {
return o1.getTotalMonthlyPremium().compareTo(o2.getTotalMonthlyPremium());
}
}

}
Loading