Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
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
13 changes: 10 additions & 3 deletions feedback.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
Your team (name of each individual participating):
How many JUnits were you able to get to pass?

Nick Nguyen
Jarrett Devereaux

How many JUnits were you able to get to pass?
We were able to pass all the JUnit tests.

Document and describe any enhancements included to help the judges properly grade your submission.
Step 1:
Step 2:
- We used the CsvSchema, CsvMapper, and ObjectReader classes to create the readCsvFile method.
- We used streaming (A newer Java feature) in place of for loops where applicable.
-


Feedback for the coding competition? Things you would like to see in future events?
- The most difficult part was getting git to cooperate.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,25 @@ public class SimpleDataToolController {
* @return List of entries from CSV file
*/
public <T> List<T> readCsvFile(String filePath, Class<T> classType) {
return null;
List<T> entries = new ArrayList<>();
try
{
CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();
CsvMapper mapper = new CsvMapper();
mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
ObjectReader oReader = mapper.readerFor(classType).with(bootstrapSchema);
Reader reader = new FileReader(filePath);
MappingIterator<T> mi = oReader.readValues(reader);
while (mi.hasNext())
{
entries.add(mi.next());
}
}
catch (Exception e)
{
e.printStackTrace();
}
return entries;
}

/**
Expand All @@ -41,7 +59,9 @@ public <T> List<T> readCsvFile(String filePath, Class<T> classType) {
* @return number of open claims
*/
public int getNumberOfOpenClaims(List<Claim> claims) {
return 0;
return (int) claims.stream()
.filter(claim -> claim.getIsClaimOpen() == true)
.count();
}

/**
Expand All @@ -52,7 +72,10 @@ public int getNumberOfOpenClaims(List<Claim> claims) {
* @return number of customer for agent
*/
public int getNumberOfCustomersForAgentId(String filePath, int agentId) {
return 0;
List<Customer> customers = readCsvFile(filePath, Customer.class);
return (int) customers.stream()
.filter(customer -> customer.getAgentId() == agentId)
.count();
}

/**
Expand All @@ -63,7 +86,10 @@ public int getNumberOfCustomersForAgentId(String filePath, int agentId) {
* @return number of customer for agent
*/
public int getNumberOfAgentsForState(String filePath, String state) {
return 0;
List<Agent> agents = readCsvFile(filePath, Agent.class);
return (int) agents.stream()
.filter(agent -> agent.getState().equals(state))
.count();
}

/**
Expand All @@ -74,7 +100,10 @@ public int getNumberOfAgentsForState(String filePath, String state) {
* @return float of monthly premium
*/
public double sumMonthlyPremiumForCustomerId(List<Policy> policies, int customerId) {
return 0d;
return policies.stream()
.filter(policy -> policy.getCustomerId() == customerId)
.mapToDouble(policy -> policy.getPremiumPerMonth())
.sum();
}

/**
Expand All @@ -90,6 +119,31 @@ public double sumMonthlyPremiumForCustomerId(List<Policy> policies, int customer
*/
public Integer getNumberOfOpenClaimsForCustomerName(String filePathToCustomer, String filePathToPolicy,
String filePathToClaims, String firstName, String lastName) {

/*Read Customer, Policy, Claims csv files*/
List<Customer> customers = readCsvFile(filePathToCustomer, Customer.class);
List<Policy> policies = readCsvFile(filePathToPolicy, Policy.class);
List<Claim> claims = readCsvFile(filePathToClaims, Claim.class);

getNumberOfOpenClaims(claims);

Optional<Customer> customer = customers
.stream()
.filter(c -> c.getFirstName().equals(firstName) && c.getLastName().equals(lastName))
.findFirst();

if (customer.isPresent()) {
List<Policy> customerPolicies = policies
.stream()
.filter(policy -> policy.getCustomerId() == customer.get().getId())
.collect(Collectors.toList());
List<Claim> customerClaims = claims
.stream()
.filter(claim -> customerPolicies.stream().anyMatch(policy -> policy.getId() == claim.getPolicyId()))
.collect(Collectors.toList());

return getNumberOfOpenClaims(customerClaims);
}
return null;
}

Expand All @@ -102,7 +156,71 @@ public Integer getNumberOfOpenClaimsForCustomerName(String filePathToCustomer, S
* @return String of language
*/
public String getMostSpokenLanguageForState(String customersFilePath, String state) {
return null;

List<Customer> customers = readCsvFile(customersFilePath, Customer.class);
Map<String,Integer> language = new HashMap<>();

List<Customer> customers_in_state = customers
.stream()
.filter(customer -> customer.getState().equals(state))
.collect(Collectors.toList());



for (Customer customer : customers_in_state)
{
if (!customer.getPrimaryLanguage().equals("English"))
{
if (language.containsKey(customer.getPrimaryLanguage()))
{
language.put
(
customer.getPrimaryLanguage(),
language.get(customer.getPrimaryLanguage())+1
);
}
else
{
language.put
(
customer.getPrimaryLanguage(),
1
);
}
}

if (!customer.getSecondaryLanguage().equals(""))
{
if (!customer.getSecondaryLanguage().equals("English"))
{
if (language.containsKey(customer.getSecondaryLanguage()))
{
language.put
(
customer.getSecondaryLanguage(),
language.get(customer.getSecondaryLanguage())+1
);
}
else
{
language.put
(
customer.getSecondaryLanguage(),
1
);
}
}
}
}
Map.Entry<String, Integer> maxEntry = null;
for (Map.Entry<String, Integer> entry : language.entrySet())
{
if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0)
{
maxEntry = entry;
}
}
return maxEntry.getKey();
}

/**
Expand All @@ -113,9 +231,47 @@ public String getMostSpokenLanguageForState(String customersFilePath, String sta
* @return Customer that has the highest, total premium as Customer object
*/
public Customer getCustomerWithHighestTotalPremium(String customersFilePath, List<Policy> policies) {
List<Customer> customers = readCsvFile(customersFilePath, Customer.class);
Map<Integer, Double> customerPremiums = new HashMap<>();
for (Customer customer : customers) {
if (customerPremiums.containsKey(customer.getId()))
{
customerPremiums.put
(
customer.getId(),
customerPremiums.get(customer.getId()) + sumMonthlyPremiumForCustomerId(policies, customer.getId())
);
}
else
{
customerPremiums.put
(
customer.getId(),
sumMonthlyPremiumForCustomerId(policies, customer.getId())
);
}
}
Map.Entry<Integer, Double> maxEntry = null;
for (Map.Entry<Integer, Double> entry : customerPremiums.entrySet())
{
if (maxEntry == null ||
entry.getValue() > (maxEntry.getValue()))
{
maxEntry = entry;
}

}
for (Customer customer : customers)
{
if (customer.getId() == maxEntry.getKey())
{
return customer;
}
}
return null;
}


/**
* Returns the total number of open claims for a given state
*
Expand All @@ -127,7 +283,36 @@ public Customer getCustomerWithHighestTotalPremium(String customersFilePath, Lis
*/
public int getOpenClaimsForState(String customersFilePath, String policiesFilePath, String claimsFilePath,
String state) {
return 0;

List <Claim> claims = readCsvFile(claimsFilePath, Claim.class);
List <Customer> customers = readCsvFile(customersFilePath, Customer.class);
List <Policy> policies = readCsvFile(policiesFilePath, Policy.class);

List <Claim> open_claims = claims
.stream()
.filter(claim -> claim.getIsClaimOpen())
.collect(Collectors.toList());

List <Policy> open_claims_policies = policies
.stream()
.filter(policy -> open_claims
.stream()
.anyMatch(claim -> claim.getPolicyId() == policy.getId()))
.collect(Collectors.toList());

List <Customer> open_claims_customers = customers
.stream()
.filter(customer -> open_claims_policies
.stream()
.anyMatch(policy -> policy.getCustomerId() == customer.getId()))
.collect(Collectors.toList());

int open_claims_state = (int) open_claims_customers
.stream()
.filter(customer -> customer.getState().equals(state))
.count();

return open_claims_state;
}

/**
Expand All @@ -140,6 +325,28 @@ public int getOpenClaimsForState(String customersFilePath, String policiesFilePa
*/
public Map<Integer, Double> buildMapOfAgentPremiums(
String customersFilePath, String policiesFilePath) {
return null;

List<Customer> customers = readCsvFile(customersFilePath, Customer.class);
List<Policy> policies = readCsvFile(policiesFilePath, Policy.class);

Map<Integer,Double> agent = new HashMap<>();
for (Customer customer : customers)
{
if (agent.containsKey(customer.getAgentId()))
{
agent.put
(
customer.getAgentId(),
agent.get(customer.getAgentId())+sumMonthlyPremiumForCustomerId(policies,customer.getId())
);
} else {
agent.put
(
customer.getAgentId(),
sumMonthlyPremiumForCustomerId(policies,customer.getId())
);
}
}
return agent;
}
}
}