Programming Exercise 3-9 | Instructions Insurance.java+ 1 import java.util.Scann
ID: 3743537 • Letter: P
Question
Programming Exercise 3-9 | Instructions Insurance.java+ 1 import java.util.Scanner 2 class Insurance [ The Harrison Group Life Insurance LCompany computes annual policy public static void main (String args[]) 4 // Write your code here 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 6 7public static int calculatePreium(int curr, int birth) // ite your code here 16 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 both to a method that calculates and returns the premium amount, and then display the returned amount. year. Pass GRADING Write your Java code in the coding area orn the right. Use the Run Code button to execute and run the code and the Test button to run a series of pre-configured tests against your project. Once you are happy with the test results, click Grade to submit your project for grading.Explanation / Answer
Java code:
import java.util.Scanner;
public class Insurance {
public static void main(String args[]){
//Scanner class object to read inputs from user
Scanner scan = new Scanner(System.in);
//prompt the user for the current year
System.out.print("Enter current year:");
int currentYear = scan.nextInt();
//prompt the user for birth year
System.out.print("Enter birth year:");
int birthYear = scan.nextInt();
//passing both variables to method
int premiumAmount = calculatePremium(currentYear,birthYear);
//displaying the premium amount
System.out.println("Premimum amount: $"+premiumAmount);
}
public static int calculatePremium(int curr,int birth) {
//calculate decade using curr and birth
int decade = curr-birth;
//finding out number of decades
decade = decade/10;
//calculating premium amount using decades
int premimumAmount = (decade+15)*20;
//returning preimum amount back to main method
return premimumAmount;
}
}
Output: Test case 1
Enter current year:2018
Enter birth year:1984
Premimum amount: $360
Output: Test case 2
Enter current year:2018
Enter birth year:1901
Premimum amount: $520
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.