Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java Insurance program homework help

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Java Insurance program homework help

    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;
    }
     
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java Insurance program homework help

    Use the provided sample run as a guide. With that and the very explicit instructions, it's hard to imagine how you could be stuck.

  3. #3
    Junior Member
    Join Date
    Apr 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Insurance program homework help

    I know it is a late reply but I guess I solved your problems because it was two bugs: I believe it was...

    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");
    int numDUI = input.nextInt();
    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;
    }

    }
    }
    }

    --- Update ---

    I know it is a late reply but I guess I solved your problems because it was two bugs: I believe it was...

    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");
    int numDUI = input.nextInt();
    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;
    }

    }
    }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Insurance program homework help

    4 year old thread closed
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 8
    Last Post: February 12th, 2013, 05:45 AM
  2. need help with phone number program for homework
    By stevolabo in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2012, 07:34 PM
  3. The Rational Class Program [HOMEWORK HELP]
    By FCarlton24 in forum Object Oriented Programming
    Replies: 1
    Last Post: October 18th, 2011, 12:31 PM
  4. [SOLVED] Could someone help me find my errors on this program?? (homework)
    By r19ecua in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 20th, 2011, 10:25 PM
  5. need help with homework program...thanks
    By robertsbd in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 5th, 2010, 03:12 PM