Answer to Question #65067 in Java | JSP | JSF for Maya

Question #65067
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 and a birth year. Pass both to a method that calculates and returns the premium amount, and then display the returned amount.

Save the class as Insurance.java. Don’t forget to create the application/project InsuranceTest.java Class that has the main method and an object to use the Insurance class.
1
Expert's answer
2017-02-08T07:17:35-0500

public class Insurance {
private int currentYear;
private int birthClient;
private int premiumAmount;

public Insurance(int birthClient, int currentYear) {
this.birthClient = birthClient;
this.currentYear = currentYear;
}

public int getCurrentYear() {
return currentYear;
}

public int getPremiumAmount() {
return premiumAmount;
}

public void setCurrentYear(int currentYear) {
this.currentYear = currentYear;
}

public int getBirthClient() {
return birthClient;
}

public void setBirthClient(int birthClient) {
this.birthClient = birthClient;
}

public void calcPremiumAmount() {
premiumAmount = (((currentYear - birthClient) / 10) + 15) * 20;
}
}
-------------------------------------------------------------------------------------------------------------
import java.util.Scanner;

public class InsuranceTest {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int currentYear,birthClient;

System.out.print("Enter current year: ");
currentYear = sc.nextInt();
System.out.print("Enter client bith year: ");
birthClient = sc.nextInt();

Insurance client = new Insurance(birthClient,currentYear);
client.calcPremiumAmount();//calculate premium amount
System.out.println("Premium amount: $" + client.getPremiumAmount());//return premium amount
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS