In: Computer Science
You are creating a program for a huge life insurance company. Yearly payments are determined by the amount of coverage offered, the age of the customer, and by whether the customer has a pre-existing sickly condition. Payments are calculated as follows:
Ages less than 20 – Yearly premium is 1/2000 th of the total premium. (example: a $500,000 policy would have a $250 yearly premium.)
Ages between 20 and 40 – Yearly premium is 1/1000 th of the total premium.
Ages between 40 and 60 - Yearly premium is 1/800 th of the total premium.
Ages greater than 60 – Yearly premium is 1/500 th of the total premium.
If the customer is sickly or has a risky pre-existing condition, the yearly payment is 2* the value of the normal premium.
Use conditional expressions to determine if a customer is sickly or not.
Use the following prompt for collecting user input:
“ Enter the appropriate number or the range for the customer:
1 : 1 – 20 years old
2 : 20 – 40 years old
3 : 40 – 60 years old
4 : 60 years or older
“
Use conditional expressions for evaluating
In case of any concern drop me a comment.
I wrote code in java language and try to satisfy all the conditions.
import java.util.Scanner;
public class Insurance {
// Main method for executing the code
public static void main(String[] args) {
int yearlyPremium = 0;
// Creating scanner class object to read the input from keyboard
Scanner sc = new Scanner(System.in);
System.out.println("Enter the coverage amount offered ");
// Getting coverage value and stored in variable
int coverage = sc.nextInt();
System.out.println("Is customer sickly or has a risky pre-existing condition \n Press 1 for Yes or 0 for No ");
int risk = sc.nextInt();
if(risk ==1) // check customer is sick or not
{
yearlyPremium = 2*(coverage/800); //twice of normal premium for sick
}
else // Calculate the premium based on age
{
System.out.println("Enter the appropriate number or the range for the customer:");
System.out.println(" 1 : 1 – 20 years old \n 2 : 20 – 40 years old \n 3 : 40 – 60 years old \n 4 : 60 years or older");
int ageRange = sc.nextInt();
if(ageRange == 1)
yearlyPremium = (coverage/2000);
if(ageRange == 2)
yearlyPremium = (coverage/1000);
if(ageRange == 3)
yearlyPremium = (coverage/800);
if(ageRange == 4)
yearlyPremium = (coverage/500);
}
System.out.println("The yearly premium is " +yearlyPremium+"$.");
}
}