May 2021 6 82 Report
JAVA - car insurance program?

I am trying to work out the following question:

write a program to determine the cost of car insurance premium based on the drivers age and the number of accidents they have had.

The basic insurance charge is £500. There is a surcharge of £100 if the driver is under 25 and additional surcharge for accidents:

1 accident= £50 surcharge

2 accidents= 125 surcharge

3 accidents= 225 surcharge

4 accidents- 375 surcharge

5 accidents= 575 surcharge

6 or more= no insurance

Here is my source code:

import java.util.Scanner;

public class carinsurance{

public static void main(String[]args){

Scanner input=new Scanner(System.in);

double age, accidents, accident, surcharge, basic, total;

age= accidents= surcharge=accident=basic=total=0;

System.out.println("Please insert your age");

age=input.nextDouble();

if (age>=25){

System.out.println ("You dont have to pay the £100 surcharge");

}

else if (age<25)

{

System.out.println ("you are going to have to pay the £100 surcharge" + basic);

total=(100+500);

System.out.println ("How many accidents have you had?");

}

accidents=input.nextDouble();

if ((accidents>=1))

{

System.out.println ("you are going to have to pay £50 accident surcharge" + basic);

total=(50+300);

}

else if ((accidents>=2 )){

System.out.println ("you are going to have to pay £125 surcharge" + basic);

}

else if ((accidents>=3 )){

System.out.println("you are going to have to pay £225 surcharge" + basic);

total=(225+300);

}

if ((accidents>=4 && accidents<=4)){

System.out.println("you are going to have to pay £375 surcharge" + basic);

}

else if ((accidents>=5 ))

{

System.out.println("you are going to have to pay £575 surcharge" + basic);

total=(575+300);

}

else if ((accidents>=6)){

System.out.println("Sorry you dont qualify for any insurance!");

total=basic+surcharge;

}

}

}

This code when run asks for you to insert your age, if you put 25 it will say you dont have to pay the £100 surcharge, however it wont ask how many accidents you have had whereas if you put an age under 25 it says that you have to pay the £100 surcharge and also asks how many accidents you have had, but does still not display a total of how much somebody would have to pay.

Can anyone see where I am going wrong? im totally stumped as I thought all of the relevant sode was there.

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 QUIZLS.COM - All rights reserved.