In: Computer Science
Des/ign, implement, (Auto, Home, Life) as classes and test them, that represent different insurance policies. A policy contains information used by an insurance company to provide financial assi/stance in the event of an accident. It also contains information used to compute how much money, also called acommission. Develop instance variables, constructors, get/set methods, and a toString method for each class. Create a driver class called PolicyTest, whose main method creates objects from each type of class, sets each object with sample data for the information below, and prints the commis/sion totals based on the formulas below. You are not required to prompt a user for the information in this.
Auto insurance policy
Policy information includes:
- name of insured
- make and model of automobile
- amount of liability coverage in dollars
- amount of collision coverage in dollars
Sales commission is based on the formula:
commission = (liability + collision) * 30%
Home insurance policy
Policy information includes:
- name of insured
- house square footage
- amount of dwelling coverage in dollars
- amount of contents coverage in dollars
- amount of liability coverage in dollars
Sales commission is based on the formula:
commission = (liability * 30%) + ( (dwelling + contents) * 20%
)
Life insurance policy
Policy information includes:
- name of insured
- age of insured
- amount of term life coverage in dollars
Sales commission is based on the following formula:
commission = term life * 20%
Auto.java
public class Auto {
private String name;
private String make;
private String model;
private double liability;
private double collision;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public double getLiability() {
return liability;
}
public void setLiability(double liability) {
this.liability = liability;
}
public double getCollision() {
return collision;
}
public void setCollision(double collision) {
this.collision = collision;
}
public Auto(String name,String make,String model,double liability,double collision) {
this.name = name;
this.make = make;
this.model = model;
this.liability = liability;
this.collision = collision;
}
@Override
public String toString() {
return "Auto [name=" + name + ", make=" + make + ", model=" + model
+ ", liability=" + liability + ", collision=" + collision + "]";
}
public double getCommision(){
double commision = (liability + collision)*30 /100;
return commision;
}
}
Home.java
public class Home {
private String name;
private double homesquare;
private double liability;
private double dwelling;
private double content;
public Home(String name,double homesquare,double liability, double dwelling, double content) {
this. name = name;
this. homesquare = homesquare;
this. liability = liability;
this.dwelling = dwelling;
this.content = content;
}
public double getCommision(){
double cs = (liability * 0.3) + ( (dwelling + content) * 0.2 );
return cs;
}
@Override
public String toString() {
return "Home [name=" + name + ", homesquare=" + homesquare
+ ", liability=" + liability + ", dwelling=" + dwelling
+ ", content=" + content + "]";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getHomesquare() {
return homesquare;
}
public void setHomesquare(double homesquare) {
this.homesquare = homesquare;
}
public double getLiability() {
return liability;
}
public void setLiability(double liability) {
this.liability = liability;
}
public double getDwelling() {
return dwelling;
}
public void setDwelling(double dwelling) {
this.dwelling = dwelling;
}
public double getContent() {
return content;
}
public void setContent(double content) {
this.content = content;
}
}
Life.java
public class Life {
private String name;
private int age;
private double term;
public Life(String name,int age, double term) {
this. name = name;
this.age = age;
this.term = term;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getTerm() {
return term;
}
public void setTerm(double term) {
this.term = term;
}
@Override
public String toString() {
return "Life [name=" + name + ", age=" + age + ", term=" + term + "]";
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getCommision(){
double cs = term*0.2;
return cs;
}
}
Policy Test.java
ublic class Policytest {
public static void main(String[] args) {
Auto at = new Auto("shiv","suzuki","A500",0.5,0.6);
Home hm = new Home("shiv",5.5,0.6,0.7,0.8);
Life lf = new Life("shiv",27,5);
System.out.println(at+ "Auto commision"+" "+at.getCommision());
System.out.println(hm+ "Home commision"+" "+hm.getCommision());
System.out.println(lf+ "Life commision"+" "+lf.getCommision());
}
Output
Auto [name=shiv, make=suzuki, model=A500, liability=0.5,
collision=0.6]Auto commision 0.33
Home [name=shiv, homesquare=5.5, liability=0.6, dwelling=0.7,
content=0.8]Home commision 0.48000000000000004
Life [name=shiv, age=27, term=5.0]Life commision 1.0