Question: (****JAVA****) *I added my code to the bottom. Please make sure to check/correct any mistakes I've made with my code. I'm having problems with my
(****JAVA****)
*I added my code to the bottom. Please make sure to check/correct any mistakes I've made with my code. I'm having problems with my if and else statements trying to match with the directions of this code, especially the calculations. Thank you!*
The HiRisq Insurance company determines auto insurance rates based on a drivers age, number of tickets in the last three years, and the value of the car. Write a program that asks the user for her age, the number of traffic tickets she has received in the last three years, and the value of her car. Once those three values have been read in, your program will calculate and print the monthly premium that this driver must pay to be insured.
Use the following rules: The base premium is 5 percent of the value of the car. Drivers under 25 years old pay 15 percent more and drivers from 25 through 29 pay 10 percent more. A driver with one ticket pays 10 percent over the premium already figured. Two tickets draws a 25 percent extra charge; three tickets adds 50 percent; and drivers with more than three tickets are refused.
Notes:
To calculate the premium, first apply the base rate of 5% of the value of the car to get the base premium. Then add a percentage of that premium based on the age of the driver. Finally add a percentage of that premium for the number of tickets. For example, for the driver age 19:
Premium = (850 * .05)* 1.15 * 1.50 = 73.3125 ^ ^ ^ car value age tickets
Structure the branches so that you have NO code duplication.
In order to receive full credit:
Have no repeated code in your program.
Do not test for conditions that you know are true.
CODE: *I added my code to the bottom. Please make sure to check/correct any mistakes I've made with my code. I'm having problems with my if and else statements trying to match with the directions of this code, especially the calculations. Thank you!*
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int userAge;
int numTickets ;
int vCar;
double premium = 0;
System.out.print("Driver's age? ");
userAge = input.nextInt();
System.out.print("Number of Tickets? ");
numTickets = input.nextInt();
System.out.print("Value of car? ");
vCar = input.nextInt();
if(numTickets > 3) {
System.out.println("Insurance denied.");
return;
}
if (userAge < 25){
premium = (vCar * 0.05) * userAge * numTickets;
}
else if (userAge > 25 && userAge < 29) {
premium = (vCar * 0.10) * userAge * numTickets;
}
else if (numTickets == 1) {
premium = (vCar * 0.05) * userAge * numTickets + 0.10;
}
else if (numTickets == 2) {
premium = (vCar * 0.05) * userAge * numTickets + 0.25;
}
else if (numTickets == 3) {
premium = (vCar * 0.05) * userAge * numTickets + 0.50;
}
System.out.println(premium);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
