Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/6 calculate loss ratio #7

Merged
merged 4 commits into from
May 29, 2023
Merged
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
17 changes: 15 additions & 2 deletions src/Contract/Contract.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package Contract;

import Customer.Customer;
import Insurance.Insurance;

import java.util.Date;
import java.util.HashMap;

public class Contract {
private int id;
Expand Down Expand Up @@ -161,8 +165,17 @@ public boolean reexamine(String underwritingState, int employeeID, int insurance
return false;
}

public boolean calculateLossRatio(int insuranceID, int customerID){
return false;
public HashMap<String, String> calculateLossRatio(Insurance insurance, Customer customer){
HashMap<String, String> result = new HashMap<>();
double estimatedEarning, estimatedPayment;
estimatedEarning = (this.period/this.paymentTerm) * this.premium;
estimatedPayment = this.paymentRate * insurance.getPrice();
this.lossRatio = estimatedPayment/estimatedEarning;
result.put("estimatedEarning", Double.toString(estimatedEarning));
result.put("estimatedPayment", Double.toString(estimatedPayment));
result.put("lossRatio", Double.toString(this.lossRatio));
result.put("isResult", "true");
return result;
}

public double calculatePremium(int insuranceID, double paymentRate){
Expand Down
116 changes: 113 additions & 3 deletions src/Contract/Reinsurance.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,130 @@
package Contract;

import Customer.Customer;
import Insurance.Insurance;

import java.util.HashMap;

public class Reinsurance {

private HashMap<String, String> reinsuranceContractDetails;
private int id;
private HashMap<String, String> reinsuranceCompanyManagerInfo;
//private HashMap<String, String> reinsuranceContractDetails;
private int period;
private double paymentAmount;
private double contractRate;
private double lossRatio;
//private HashMap<String, String> reinsuranceCompanyManagerInfo;
private String reinsuranceCompanyName;
private String reinsuranceCompanyManagerName;
private String reinsuranceCompanyManagerContract;
private int contractID;
private String contractResult;

private String rejectionReasons;

public Reinsurance(){
public double getContractRate() {
return contractRate;
}

public void setContractRate(double contractRate) {
this.contractRate = contractRate;
}

public double getLossRatio() {
return lossRatio;
}

public void setLossRatio(double lossRatio) {
this.lossRatio = lossRatio;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getPeriod() {
return period;
}

public void setPeriod(int period) {
this.period = period;
}

public double getPaymentAmount() {
return paymentAmount;
}

public void setPaymentAmount(double paymentAmount) {
this.paymentAmount = paymentAmount;
}

public String getReinsuranceCompanyName() {
return reinsuranceCompanyName;
}

public void setReinsuranceCompanyName(String reinsuranceCompanyName) {
this.reinsuranceCompanyName = reinsuranceCompanyName;
}

public String getReinsuranceCompanyManagerName() {
return reinsuranceCompanyManagerName;
}

public void setReinsuranceCompanyManagerName(String reinsuranceCompanyManagerName) {
this.reinsuranceCompanyManagerName = reinsuranceCompanyManagerName;
}

public String getReinsuranceCompanyManagerContract() {
return reinsuranceCompanyManagerContract;
}

public void setReinsuranceCompanyManagerContract(String reinsuranceCompanyManagerContract) {
this.reinsuranceCompanyManagerContract = reinsuranceCompanyManagerContract;
}

public int getContractID() {
return contractID;
}

public void setContractID(int contractID) {
this.contractID = contractID;
}

public String getContractResult() {
return contractResult;
}

public void setContractResult(String contractResult) {
this.contractResult = contractResult;
}

public String getRejectionReasons() {
return rejectionReasons;
}

public void setRejectionReasons(String rejectionReasons) {
this.rejectionReasons = rejectionReasons;
}

public Reinsurance(){

}
public HashMap<String, String> calculateLossRatio(Contract contract, Insurance insurance){
HashMap<String, String> result = new HashMap<>();
double estimatedEarning, estimatedPayment;
estimatedEarning = (contract.getPeriod()/contract.getPaymentTerm()) * contract.getPremium();
estimatedPayment = (contract.getPaymentRate() * insurance.getPrice() * (1-this.contractRate)) + ((this.period) * this.paymentAmount);
this.lossRatio = estimatedPayment/estimatedEarning;
result.put("estimatedEarning", Double.toString(estimatedEarning));
result.put("estimatedPayment", Double.toString(estimatedPayment));
result.put("lossRatio", Double.toString(this.lossRatio));
result.put("isResult", "true");
return result;
}
public HashMap<String, String> contract(HashMap<String, String> contractDetails, String reinsuracneCompanyManagerContact, HashMap<String, String> employeeInfo){
return null;
}
Expand Down
126 changes: 126 additions & 0 deletions src/Dao/ContractDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package Dao;

import Contract.Contract;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class ContractDao extends Dao{
public ContractDao(){
try {
super.connect();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void create(Contract contract){
String query = "INSERT INTO Contract VALUES(" +
contract.getContractorID()+"," +
contract.getInsuranceID()+"," +
"'"+contract.getInsuredCustomerID()+"'," +
"'"+contract.getEmployeeID()+"'," +
contract.getFee()+"," +
contract.getPremium()+"," +
contract.getPaymentRate()+"," +
contract.getPeriod()+"," +
"'"+contract.getSignedDate()+"'," +
"'"+contract.getExpirationDate()+"'," +
contract.getPaymentTerm()+"," +
contract.getLossRatio()+"," +
"'"+contract.getUnderwritingState()+"'," +
"'"+contract.getRejectionReasons()+"'" +
");";
super.create(query);
}
public Contract retrieveById(int contractID) {
String query = "SELECT * FROM Contract WHERE id = '"+
contractID+"';";
Contract contract = null;
try {
ResultSet resultSet = super.retrieve(query);
while(resultSet.next()) {
contract = new Contract();
contract.setId(resultSet.getInt("id"));
contract.setContractorID(resultSet.getInt("contractorID"));
contract.setInsuranceID(resultSet.getInt("insuranceID"));
contract.setInsuredCustomerID(resultSet.getString("insuredCustomerID"));
contract.setEmployeeID(resultSet.getString("employeeID"));
contract.setFee(resultSet.getDouble("fee"));
contract.setPremium(resultSet.getDouble("premium"));
contract.setPaymentRate(resultSet.getDouble("paymentRate"));
contract.setPeriod(resultSet.getInt("period"));
contract.setSignedDate(resultSet.getDate("signedDate"));
contract.setExpirationDate(resultSet.getDate("expirationDate"));
contract.setPaymentTerm(resultSet.getInt("paymentTerm"));
contract.setLossRatio(resultSet.getDouble("lossRatio"));
contract.setUnderwritingState(resultSet.getString("underwritingState"));
contract.setRejectionReasons(resultSet.getString("rejectionReasons"));
}
resultSet.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return contract;
}
public ArrayList<Contract> retrieveAll() {
String query = "SELECT * FROM Contract;";
ArrayList<Contract> contractList = null;
try {
ResultSet resultSet = super.retrieve(query);
contractList = new ArrayList<Contract>();
while(resultSet.next()) {
Contract contract = new Contract();
contract.setId(resultSet.getInt("id"));
contract.setContractorID(resultSet.getInt("contractorID"));
contract.setInsuranceID(resultSet.getInt("insuranceID"));
contract.setInsuredCustomerID(resultSet.getString("insuredCustomerID"));
contract.setEmployeeID(resultSet.getString("employeeID"));
contract.setFee(resultSet.getDouble("fee"));
contract.setPremium(resultSet.getDouble("premium"));
contract.setPaymentRate(resultSet.getDouble("paymentRate"));
contract.setPeriod(resultSet.getInt("period"));
contract.setSignedDate(resultSet.getDate("signedDate"));
contract.setExpirationDate(resultSet.getDate("expirationDate"));
contract.setPaymentTerm(resultSet.getInt("paymentTerm"));
contract.setLossRatio(resultSet.getDouble("lossRatio"));
contract.setUnderwritingState(resultSet.getString("underwritingState"));
contract.setRejectionReasons(resultSet.getString("rejectionReasons"));
contractList.add(contract);

}
resultSet.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return contractList;
}
public void update(Contract contract){
String query = "UPDATE Contract SET " +
"contractorID = " + contract.getContractorID() + ", " +
"insuranceID = " + contract.getInsuranceID() + ", " +
"insuredCustomerID = '" + contract.getInsuredCustomerID() + "', " +
"employeeID = '" + contract.getEmployeeID() + "', " +
"fee = " + contract.getFee() + ", " +
"premium = " + contract.getPremium() + ", " +
"paymentRate = " + contract.getPaymentRate() + ", " +
"period = " + contract.getPeriod() + ", " +
"signedDate = '" + contract.getSignedDate() + "', " +
"expirationDate = '" + contract.getExpirationDate() + "', " +
"paymentTerm = " + contract.getPaymentTerm() + ", " +
"lossRatio = " + contract.getLossRatio() + ", " +
"underwritingState = '" + contract.getUnderwritingState() + "', " +
"rejectionReasons = '" + contract.getRejectionReasons() + "'" +
"WHERE id = " + contract.getId() + ";";
super.update(query);
}
public void deleteById(int contractID){
String query = "DELETE FROM Contract WHERE id = "+contractID+";";
super.delete(query);
}
public void deleteAll(){
String query = "DELETE FROM Contract;";
super.deleteAll(query);
}

}
Loading