This is the situation that I need to write my program for. My code is attached below. I cannot figure out where to go next. Please help!
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:
· At most one accident in 5 years: No additional charge
o Multi-vehicle discount allowed using the following rules:
§ 1 vehicle: No discount
§ 2 or 3: 15% discount on the total premium
§ More than 3: 18% discount on the total premium
· Two to three accidents in 5 years: 20% add on for each vehicle
o Multi-vehicle discount allowed using the following rules:
§ 1 vehicle: No discount
§ 2 or 3: 7% discount on the total premium (base + accident markup)for that customer
§ More than 3: 10% discount on the total premium (base + accident markup)
· Four to five accidents in five years: 30% add on for each vehicle; no multi vehicle discount allowed
· More than 5 accidents in five years: No insurance given to the individual
3. DUI History: If there is a DUI conviction, the final premium is increased by 7%. The final premium before DUI mark up is calculated as Base Premium + Accident Mark up if any – Multi car discount.
The customer may want one or more vehicles per each type. Here is a sample run:
Enter number of accidents in last 5 years: 2
DUI Conviction: yes
Vehicle : car
Next Vehicle: car
Next Vehicle: Boat
Output
Number of vehicles insured: 3
Vehicle types: car, car, boat
Base premium: $891.00
Accident add-on: $178.20
Multicar discount: $74.84
DUI Mark Up: $69.60
Total Premium: $1063.96
Calculation explanations to help in the program:
Number of vehicles insured: Count of vehicles
Vehicle types: self-explanatory
Base premium: sum of applicable base premiums, in this case car+car+boat
Accident add-on: 2 accidents, hence 20% add on per vehicle
Multicar discount: 3 vehicles, hence 7% discount on premium (891+178.20)*0.07
DUI Mark Up: 7% on total premium (891+178.2-74.87)*.07
Total Premium: Base + Accident markup – Multicar discount + DUI markup
Name of the Program Class: Insurance.java
import java.util.Scanner; public class Insurance { public static void main (String [] args) { int passengerCar = 297; int lightTruck = 350; int motorCycle = 500; int boat = 297; double totalBasePremium = 0.0; double totalAccident = 0.0; double totalDiscount = 0.0; double totalInsuranceCost = 0.0; String allVehicles = ""; Scanner input = new Scanner (System.in); System.out.println("Enter the number of Vehicles"); int numVehicles = input.nextInt(); System.out.println("Enter the number of Accidents"); int numAccidents = input.nextInt(); System.out.println("Have you been convicted of DUI"); DUI = input.next(); for (int i=0; i < numVehicles; i++) { double totalBasePremuim = 0.0; double localDUI = 0.0; double totalInsurance_Cost = 0.0; System.out.println("What is the car type?"); String CarType = input.nextLine(); if (CarType.equalsIgnoreCase("passenger car")) { totalBasePremuim = passengerCar; totalBasePremuim += totalBasePremuim; } else if (CarType.equalsIgnoreCase("light truck")) { totalBasePremium = lightTruck; totalBasePremium += totalBasePremium; } else if (CarType.equalsIgnoreCase("Motor Cycle")) { totalBasePremium = motorCycle; totalBasePremium += totalBasePremium; } else if (CarType.equalsIgnoreCase("Boat")){ totalBasePremium = boat; totalBasePremium += totalBasePremium; } } }