This assignment consists of two (2) sections: A Java program file A screenshot o
ID: 661576 • Letter: T
Question
This assignment consists of two (2) sections:
A Java program file
A screenshot of the driver testing and source code of the implementation
Label each file name according to the section of the assignment for which it is written. Put both sections together in a single zip file, and submit the file.
It is a common knowledge that most households, for protection against their major perils, take out insurance on their property, automobiles, travel, and so on. Insurance premiums are often paid on a monthly basis. In this assignment, you will build an interactive Java application that will help an insurance agent generate a quote for a household. Assume that the household wants to purchase property insurance, automobile insurance, and travel insurance. The Java application must generate a quote when the agent runs the application.
The application must contain four (4) Java classes that are stated and shown in the diagram below.
The InsuranceAgent App class is an abstract class. The PropertyInsurance, AutomobileInsurance, and TravelInsurance classes inherit from the InsuranceAgentApp abstract class.
The specifications of each class are described below. The column on the left shows the class members and the column on the right provides a description of the class members. The 'S' designates a static member; the 'C' designates a constructor; and the 'A' designates an abstract member. The data types of each class member are shown on the left column.
Class Members and Their Properties
Member
Class Members and Their Properties
Member
Explanation / Answer
package com.tutai;
abstract class InsuranceAgentApp {
private String type;
protected String name;
private float totalPremium;
InsuranceAgentApp(){}
InsuranceAgentApp(String type){
this.type=type;
}
public String getType() {
return type;
}
public String getName() {
return name;
}
public float getTotalPremium() {
return totalPremium;
}
public abstract void setInsuredObjectName(String name);
public abstract void setRiskAmount(float riskAmount);
public abstract void display();
}
class PropertyInsurance extends InsuranceAgentApp{
private float riskAmount;
private float RATE=0.25f;
PropertyInsurance(String type){
super(type);
}
@Override
public void setInsuredObjectName(String name) {
this.name=name;
}
@Override
public void setRiskAmount(float riskAmount) {
this.riskAmount=riskAmount;
}
float calculatePremium(){
return (this.riskAmount*RATE)/1000.0f;
}
@Override
public void display() {
System.out.println("insuance type: "+super.getType());
System.out.println("name of insured object: "+super.getName());
System.out.println("risk amount: "+riskAmount);
System.out.println("rate: "+RATE);
}
}
class AutomobileInsurance extends InsuranceAgentApp{
private float riskAmount;
private float RATE=0.75f;
AutomobileInsurance(String type){
super(type);
}
@Override
public void setInsuredObjectName(String name) {
this.name=name;
}
@Override
public void setRiskAmount(float riskAmount) {
this.riskAmount=riskAmount;
}
float calculatePremium(){
return (this.riskAmount*RATE)/1000.0f;
}
@Override
public void display() {
System.out.println("insuance type: "+super.getType());
System.out.println("name of insured object: "+super.getName());
System.out.println("risk amount: "+riskAmount);
System.out.println("rate: "+RATE);
}
}
class TravelInsurance extends InsuranceAgentApp{
private float riskAmount;
private float RATE=0.73f;
TravelInsurance(String type){
super(type);
}
@Override
public void setInsuredObjectName(String name) {
this.name=name;
}
@Override
public void setRiskAmount(float riskAmount) {
this.riskAmount=riskAmount;
}
float calculatePremium(){
return (this.riskAmount*RATE)/1000.0f;
}
@Override
public void display() {
System.out.println("insuance type: "+super.getType());
System.out.println("name of insured object: "+super.getName());
System.out.println("risk amount: "+riskAmount);
System.out.println("rate: "+RATE);
}
}
Test Driver Program
package com.tutai;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import com.tutai.InsuranceAgentApp;
import com.tutai.AutomobileInsurance;
import com.tutai.TravelInsurance;
import com.tutai.PropertyInsurance;
public class InsuranceAgentAppTester {
public static void main(String[] args){
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader b=new BufferedReader(in);
String type="",name="";
float riskAmount;
while(true){
System.out.println("Enter P for property insurance");
System.out.println("Enter A for automobile insurance");
System.out.println("Enter T for travel insurance");
System.out.println("Enter type of insurance: ");
try {
type=b.readLine();
} catch (IOException e) {
e.printStackTrace();
}
switch(type){
case "P":
PropertyInsurance p=new PropertyInsurance(type);
System.out.println("Enter insured object name: ");
try {
name=b.readLine();
p.setInsuredObjectName(name);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Enter risk amount: ");
try {
riskAmount=Float.parseFloat(b.readLine());
p.setRiskAmount(riskAmount);
} catch (IOException e) {
e.printStackTrace();
}
p.calculatePremium();
p.display();
break;
case "A":
AutomobileInsurance a=new AutomobileInsurance(type);
System.out.println("Enter insured object name: ");
try {
name=b.readLine();
a.setInsuredObjectName(name);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Enter risk amount: ");
try {
riskAmount=Float.parseFloat(b.readLine());
a.setRiskAmount(riskAmount);
} catch (IOException e) {
e.printStackTrace();
}
a.calculatePremium();
a.display();
break;
case "T":
TravelInsurance t=new TravelInsurance(type);
System.out.println("Enter insured object name: ");
try {
name=b.readLine();
t.setInsuredObjectName(name);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Enter risk amount: ");
try {
riskAmount=Float.parseFloat(b.readLine());
t.setRiskAmount(riskAmount);
} catch (IOException e) {
e.printStackTrace();
}
t.calculatePremium();
t.display();
break;
}
System.out.println("Do you wish to continue? (Y/N) ");
try{
if(b.readLine().equals("y")||b.readLine().equals("y")){
continue;
}else{
break;
}
}catch(IOException e){
e.printStackTrace();
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.