* FEW FIXES ONLY * Assume that you are working for hypothetical insurance compan
ID: 3552792 • Letter: #
Question
* FEW FIXES ONLY *
Assume that you are working for hypothetical insurance company. This company offers insurance for 4 types of vehicles: cars, trucks, motor cycles and boats. In order to keep the program manageable, we will assume that we do not make a finer distinction among various types that can be found among each type of vehicle. For example, we do not care if it is a small car, or a big car. Your program is required to calculate the applicable insurance premium for a potential customer given the number of vehicles insured. This customer may want insurances for one or more vehicle; you do not know ahead of time the number of vehicles. Since you have no means of storing the result, you will be printing out the insurance value for each vehicle before proceeding with the calculation for the next vehicle. Once all vehicle insurances are calculated and printed, you will print a summary showing the number of vehicles insured for that person and the total premium due from the customer. You are free to choose other output lines to make the output user friendly.
1. The base premiums are:
Passenger car: $297
Light Truck: $350
Motor Cycle: $500
Boat: $297
These could be treated as Constants for this program.
2. Multi-vehicle discount: This depends on the accident history.
Accident history:
Explanation / Answer
import java.util.Scanner;
public class Insurance {
public static void main (String [] args) {
int Passenger_Car = 297;
int Light_Truck = 350;
int Motor_Cycle = 500;
int Boat = 297;
double total_base_premuim = 0.0;
int total_accident = 0;
double base_premium = 0.0;
double accident_addon = 0.0;
double multi_discount = 0.0;
double DUI_markup = 0.0;
String all_vehicles = "";
String DUI = "Yes";
int numbVehicles;
Scanner input = new Scanner (System.in);
System.out.println("Enter number of accidents in the last 5 years : ");
total_accident = input.nextInt();
System.out.println("DUI Convictions: ");
DUI = input.next();
System.out.println("How many cars do want to insure: ");
numbVehicles =input.nextInt();
string[] vehicles = string int[numbVehicles];
if (numbVehicles ==1 ){
System.out.println( "Vehicle: ");
all_vehicles = input.next();
vehicles[i]
if (all_vehicles == "car"){
total_base_premuim = Passenger_Car;
base_premium = Passenger_Car;
}
else if (all_vehicles == "truck") {
total_base_premuim = Light_Truck;
base_premuim = Light_Truck;
}
else if (all_vehicles == "Motor Cycle") {
total_base_premuim= Motor_Cycle;
base_premuim= Motor_Cycle;
}
else if (all_vehicles == "Boat"){
total_base_premuim = Boat;
base_premuim = Boat;
}
if(2<= total_accident || total_accident <=3){
Total_base_premium += Total_base_premium*0.2;
accident_addon += Total_base_premium*0.2;
if (DUI == "Yes"){
DUI_markup = base_premuim*0.07;
total_base_premuim += DUI_markup;
}
}
else if ( numbVehicles == 2 || numbVehicles == 3){
for(int i =1; i <= numbVehicles - 1; i++){
if(i == 1){
System.out.println( "Vehicle");
all_vehicles = input.next();
}
else {
System.out.println( " Next Vehicle");
all_vehicles = input.next();
}
if (all_vehicles == "car") {
if(2<= total_accident || total_accident <=3){
total_base_premuim += Passenger_Car - Passenger_Car * 0.07 + Passenger_Car * 0.2;
multi_discount += Passenger_Car*0.07
accident_addon += Passenger_Car*0.2;
}
else if (3<= total_accident || total_accident <=5){
total_base_premuim += Passenger_Car + Passenger_Car * 0.3;
accident_addon += Passenger_Car*0.3;
}
else {
total_base_premuim += Passenger_Car - Passenger_Car * 0.15;
multi_discount += Passenger_Car*0.15
}
base_premuim += Passenger_Car;
}
else if (all_vehicles == "truck") {
if(2<= total_accident || total_accident <=3){
total_base_premuim += Light_Truck - Light_Truck * 0.07 + Light_Truck * 0.2;
multi_discount += Light_Truck*0.07
accident_addon += Light_Truck*0.2;
}
else if (3<= total_accident || total_accident <=5){
total_base_premuim += Light_Truck + Light_Truck * 0.3;
accident_addon += Light_Truck*0.3;
}
else {
total_base_premuim += Light_Truck - Light_Truck * 0.15;
multi_discount += Light_Truck*0.15
}
base_premuim += Light_Truck;
}
else if (all_vehicles == "Motor Cycle") {
if(2<= total_accident || total_accident <=3){
total_base_premuim += Motor_Cycle - Motor_Cycle * 0.07 + Motor_Cycle * 0.2;
multi_discount += Motor_Cycle*0.07
accident_addon += Motor_Cycle*0.2;
}
else if (3<= total_accident || total_accident <=5){
total_base_premuim += Motor_Cycle + Motor_Cycle * 0.3;
accident_addon += Motor_Cycle*0.3;
}
else {
total_base_premuim += Motor_Cycle - Motor_Cycle * 0.15;
multi_discount += Motor_Cycle*0.15
}
base_premuim += Motor_Cycle;
}
else if (all_vehicles == "Boat"){
if(2<= total_accident || total_accident <=3){
total_base_premuim += Boat - Boat * 0.07 + Boat * 0.2;
multi_discount += Boat*0.07
accident_addon += Boat*0.2;
}
else if (3<= total_accident || total_accident <=5){
total_base_premuim += Boat + Boat * 0.3;
accident_addon += Boat*0.3;
}
else {
total_base_premuim += Boat - Boat * 0.15;
multi_discount += Boat*0.15
}
base_premuim += Boat;
}
}
if (DUI == "Yes"){
DUI_markup = base_premuim*0.07;
total_base_premuim += DUI_markup;
}
}
else {
for(int i =1; i <= numbVehicles - 1; i++){
if(i == 1){
System.out.println( "Vehicle");
all_vehicles = input.next();
}
else {
System.out.println( " Next Vehicle");
all_vehicles = input.next();
}
if (all_vehicles == "car") {
if(2<= total_accident || total_accident <=3){
total_base_premuim += Passenger_Car - Passenger_Car * 0.10 + Passenger_Car * 0.2;
multi_discount += Passenger_Car*0.10
accident_addon += Passenger_Car*0.2;
}
else if (3<= total_accident || total_accident <=5){
total_base_premuim += Passenger_Car + Passenger_Car * 0.3;
accident_addon += Passenger_Car*0.3;
}
else {
total_base_premuim += Passenger_Car - Passenger_Car * 0.15;
multi_discount += Passenger_Car*0.18
}
base_premuim += Passenger_Car;
}
else if (all_vehicles == "truck") {
if(2<= total_accident || total_accident <=3){
total_base_premuim += Light_Truck - Light_Truck * 0.10 + Light_Truck * 0.2;
multi_discount += Light_Truck*0.10
accident_addon += Light_Truck*0.2;
}
else if (3<= total_accident || total_accident <=5){
total_base_premuim += Light_Truck + Light_Truck * 0.3;
accident_addon += Light_Truck*0.3;
}
else {
total_base_premuim += Light_Truck - Light_Truck * 0.15;
multi_discount += Light_Truck*0.18
}
base_premuim += Light_Truck;
}
else if (all_vehicles == "Motor Cycle") {
if(2<= total_accident || total_accident <=3){
total_base_premuim += Motor_Cycle - Motor_Cycle * 0.10 + Motor_Cycle * 0.2;
multi_discount += Motor_Cycle*0.10
accident_addon += Motor_Cycle*0.2;
}
else if (3<= total_accident || total_accident <=5){
total_base_premuim += Motor_Cycle + Motor_Cycle * 0.3;
accident_addon += Motor_Cycle*0.3;
}
else {
total_base_premuim += Motor_Cycle - Motor_Cycle * 0.15;
multi_discount += Motor_Cycle*0.18
}
base_premuim += Motor_Cycle;
}
else if (all_vehicles == "Boat"){
if(2<= total_accident || total_accident <=3){
total_base_premuim += Boat - Boat * 0.10 + Boat * 0.2;
multi_discount += Boat*0.10
accident_addon += Boat*0.2;
}
else if (3<= total_accident || total_accident <=5){
total_base_premuim += Boat + Boat * 0.3;
accident_addon += Boat*0.3;
}
else {
total_base_premuim += Boat - Boat * 0.18;
multi_discount += Boat*0.18
}
base_premuim += Boat;
}
}
if (DUI == "Yes"){
DUI_markup = base_premuim*0.07;
total_base_premuim += DUI_markup;
}
}
System.out.println("Number of vehicles insured: " + numbVehicles);
for (int i = 0; i < numbVehicles; i++)
System.out.println("Vehicle types: " + vehicles[i]);
System.out.println("Base premium: " + numbVehicles);
System.out.println("Accident add-on: " + accident_addon);
System.out.println("Multicar discount: " + multi_discount);
System.out.println("DUI Mark Up: " + DUI_markup);
System.out.println("Total Premium: " + total_base_premuim);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.