In: Computer Science
At L's Insurance Company, a surcharge (an extra cost) is added to the insurance premium if the driver has points on his or her license. If the driver has no points, there is no surcharge. If the driver has 1 to 4 points, the surcharge is 8% of the insurance premium. If the driver has 5 to 8 points, the surcharge is 15% of the insurance premium. If the driver has 9 points, the surcharge is 18% of the insurance premium. If the driver has 10 or more points, the surcharge is 23% of the insurance premium. Write a complete Java program that includes the statements to read in the insurance premium and the number of points from the keyboard using the Scanner class. The program should then calculate the surcharge and the total cost, which is the sum of the premium and the surcharge. Use constants where applicable and format your output with System.out.printf method.
Class Name: InsuranceCost
Sample Output:
Enter insurance premium amount: #####
Enter the number of points you have: ##
Your surcharge is: $###,###.##
Your total cost for insurance is: $###,###.##
import java.util.*;
public class InsuranceCost
{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.print("Enter Insurance Premium cost : ");
int premium=s.nextInt(); //prompt user to enter premium
System.out.print("Enter the number of points you have: ");
int point=s.nextInt(); //prompt user to enter points
double surcharge=0;
if(point>0 && point<5) //check condition
surcharge=premium*0.08;
if(point>=5 && point<9) //check condition
surcharge=premium*0.15;
if(point==9) //check condition
surcharge=premium*0.18;
if(point>=10) //check condition
surcharge=premium*0.23;
System.out.println();
System.out.print("Your Surcharge is: " +surcharge); //output result
System.out.println();
System.out.print("The total cost is: " +(premium+surcharge));//output result
}
}
The above program stimulates all the requirements mentioned in
the question in Java programing language.