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.
Insurance.java
Explanation:
here is the code with the method premium taking the current year and birth year and then returning the premium amount to the main method which asks the user for the current year and birth year and shows the result.
Code:
import java.util.Scanner;
public class Insurance
{
public static int premium(int curr, int birth)
{
int age = curr - birth;
int decades = age/10;
return (decades+15)*20;
}
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.print("Enter current
year: ");
int curr = sc.nextInt();
System.out.print("Enter birth year:
");
int birth = sc.nextInt();
System.out.println("$"+premium(curr, birth));
}
}
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!