In: Computer Science
The Harrison Group Life Insurance company computes annual policy premiums based on the age the customer turns in the current calendar year. The premium is computed by taking the decade of the customer’s age, adding 15 to it, and multiplying by 20.
For example, a 34-year-old would pay $360, which is calculated by adding the decades (3) to 15, and then multiplying by 20.
Write an application that prompts a user for the current year then a birth year. Pass both to a method that calculates and returns the premium amount, and then display the returned amount.
import java.util.Scanner;
class Insurance {
public static void main (String args[]) {
// Write your code here
}
public static int calculatePremium(int curr, int birth) {
// Write your code here
}
}
Java Code:
import java.util.*;
class Main {
public static void main (String args[]) {
Scanner sc=new Scanner(System.in);
int curr,birth;
System.out.print("Enter Current year: ");
curr=sc.nextInt();
System.out.print("Enter Birth year: ");
birth=sc.nextInt();
System.out.print("Total premium is : $"+calculatePremium(curr,birth));
}
public static int calculatePremium(int curr, int birth) {
int age=curr-birth;
int decade=age/10;
int premium=(decade+15)*20;
return premium;
}
}