Insurance Premium Calculation Engine | Function Functional Interface | Java 8 Real-Time Project

 Hi All,

Insurance Premium Calculation Engine | Function Functional Interface | Java 8 Real-Time Project

Today I have released new video on "Insurance Premium Calculation Engine | Function Functional Interface | Java 8 Real-Time Project"

This is frequently asked question in Java Interview.

Please watch full video, share, like and Subscribe Youtube channel and press bell icon. So you will get latest video notification.


 



 package org.practice.basicprgms;


import java.util.Arrays;

import java.util.List;


public class InsurancePremiumDemo {


public static void main(String[] args) {

List<InsuranceCustomer> insuranceCustomers =

Arrays.asList(

new InsuranceCustomer("Shreya",22,true,true,false,6),

new InsuranceCustomer("Aman",35,true,false,true,3),

new InsuranceCustomer("Shruti",65,false,true,false,8),

new InsuranceCustomer("Apurva",28,false,false,false,2),

new InsuranceCustomer("Rutuwik",22,false,true,false,2),

new InsuranceCustomer("Arpita",70,true,false,true,2)

);

insuranceCustomers.forEach(customer ->

System.out.println("Customer Name : "+ customer.getName() + " : "+

InsurancePremiumService.calculatePremium.apply(customer)));

}

}


package org.practice.basicprgms;


import java.util.function.Function;


public class InsurancePremiumService {


public static Function<InsuranceCustomer, Double> calculatePremium = customer ->

{

double premium;

if(customer.getAge() < 25)

premium = 10000;

else if(customer.getAge() > 25 && customer.getAge() <= 40)

premium = 15000;

else if(customer.getAge() > 40 && customer.getAge() <= 60)

premium = 20000;

else

premium = 25000;

if(!customer.isClaim())

premium -= premium * 10 /100;

if(customer.isEarlyBird())

premium -= premium * 5 /100;

if(customer.isSmoker())

premium += 1000;

if(customer.getNoOfPolicyYears() > 5)

premium -= 500;

return premium;

};

}


package org.practice.basicprgms;


public class InsuranceCustomer {


private String name;

private int age;

private boolean claim;

private boolean earlyBird;

private boolean smoker;

private int noOfPolicyYears;

public InsuranceCustomer() {

super();

}


public InsuranceCustomer(String name, int age, boolean claim, boolean earlyBird, boolean smoker, int noOfPolicyYears) {

super();

this.name = name;

this.age = age;

this.claim = claim;

this.earlyBird = earlyBird;

this.smoker = smoker;

this.noOfPolicyYears = noOfPolicyYears;

}


public String getName() {

return name;

}


public void setName(String name) {

this.name = name;

}


public int getAge() {

return age;

}


public void setAge(int age) {

this.age = age;

}


public boolean isClaim() {

return claim;

}


public void setClaim(boolean claim) {

this.claim = claim;

}


public boolean isEarlyBird() {

return earlyBird;

}


public void setEarlyBird(boolean earlyBird) {

this.earlyBird = earlyBird;

}


public boolean isSmoker() {

return smoker;

}


public void setSmoker(boolean smoker) {

this.smoker = smoker;

}


public int getNoOfPolicyYears() {

return noOfPolicyYears;

}


public void setNoOfPolicyYears(int noOfPolicyYears) {

this.noOfPolicyYears = noOfPolicyYears;

}


@Override

public String toString() {

return "Customer [name=" + name + ", age=" + age + ", claim=" + claim + ", earlyBird=" + earlyBird + ", smoker="

+ smoker + ", noOfPolicyYears=" + noOfPolicyYears + "]";

}

}




Post a Comment

0 Comments