Background
Employees often have to pick among several health insurance plans offered by their employer. Different plans are better for different circumstances, like whether or not you are covering a family and the amount of doctor visits you expect to make. For our purposes, there are three attributes of an insurance plan that are important:
The premium: this is how much you have to pay for a year of insurance.
The deductible: this is how much you have to pay for your doctor’s bills before insurance will start paying anything. For example, if you have a $1000 deductible, then your first $1000 worth of doctor’s bills during the year will be your responsibility to pay. If you have less than $1000 in expenses during the year, then your insurance will not pay anything toward your bills. Otherwise, you pay the first $1000 and you and your insurance company split the cost for the rest of the bills. How those bills are split is determined by the…
The coinsurance: this is a percentage, like 20%. After you have “met your deductible”–that is, paid doctor’s bills totaling your deductible amount–then the remaining bills for that year are split. You pay the coinsurance, and your insurance company covers the rest.
Here are a few examples:
1. My plan has $5000 premium, $1000 deductible, and 20% coinsurance.
If I have no medical bills, then my health care costs are $5000 (i.e., just the premium).
If I have $500 in medical bills, then I pay all of those (because they are less than the deductible), plus the premium. My health care costs are $5500.
If I have $1002 in medical bills, then I pay the premium, plus my $1000 deductible, plus 20% of the bills over the deductible (20% of $2 is $0.40). Thus, my health care costs are $6000.40.
If I have $15000 in medical bills, then I pay the premium, plus my $1000 deductible, plus 20% of the bills over the deductible (20% of $14000 is $2800). Thus, my health care costs are $8800.
2. In scenario 2, suppose my plan has $3000 premium, $4000 deductible, and 25% coinsurance.
If I have no medical bills, then my health care costs are $3000 (i.e., just the premium).
If I have $500 in medical bills, then I pay all of those (because they are less than the deductible), plus the premium. My health care costs are $3500.
If I have $1002 in medical bills, then I pay all of those (because they are less than the deductible), plus the premium. My health care costs are $4002.
If I have $15000 in medical bills, then I pay the premium, plus my $4000 deductible, plus 25% of the bills over the deductible (25% of $11000 is $2750). Thus, my health care costs are $9750.
Project Description
For this project, you will build a program that computes the health care costs given the premium, deductible, coinsurance, and total medical bills. We will be working with two pre-defined health care plans, as well as letting the user enter their own parameters. Here are the two plans:
Premium | Deductible | Coinsurance | |
Alphex | $5000 | $1000 | 20% |
Glamron | $3000 | $4000 | 25% |
Analysis
As you gain experience with programming, you will be able to analyze the description above and create a program to compute the health care costs. In this first project, however, we will guide you through the analysis part and help you design your program.
One of the first steps in analysis is determining the inputs that your program needs and the outputs it will produce.Before reading the next part of the description, take a minute to write down the inputs and outputs.
You should have written down the following:
Inputs: Premium, deductible, coinsurance, amount of medical bills
Output: health care costs
Design
As with the analysis, as you gain experience with programming you will reach the point where you can complete the design on your own. This is where you figure out the algorithm (i.e., the steps the computer needs to take) for computing the health care costs for a given premium, deductible, coinsurance, and amount of medical bills. You can use the definitions and examples above to figure this out, along with the requirements that follow.
Your program should meet the following specifications. (The amount of points for each part is in square brackets).
[10 pts] As with all your code, correct compilation is critical.
Commenting and style
[3 pts] Comments should be clearly written with correct grammar and spelling.
[3 pts] Indentation and general appearance should be consistent and make the code easy to read.
[2 pts] You should write a comment for each major piece of computation. For example,
// Determine the health care plan
[2 pts] You should also write a comment at the top of your file with the following content:
/*
* <your name>
* CS16000 Spring 2015
* Project 1: Health Care Calculator
*
* Description: <summarize the purpose of the program here>
*/
[1 pt] The program should consist of one class, called HealthCareCalculator
[1 pt] The class should contain only the main method.
Variables in the main method
[5 pts] The main method should include variables called premium, deductible, coinsurance, and bills. You should determine the appropriate types for those variables.
[5 pts] It should also contain variables for each attribute of the two health care plans listed above (i.e., 6 variables total). Choose clear, understandable names for these variables. These should be named constants (i.e., there is a Java keyword to make these constants). This is the only place where you should use numeric constants in your program.
You can define other variables as needed, but they must all be within the main method.
The main method should carry out the following tasks in this order:
Declare variables as needed
[2 pts] Declare and instantiate a Scanner object to read data from the console
[6 pts] Solicit the health care plan name from the user via the console with the message “Enter the name of the health care plan: “
[8 pts] Run a switch statement on the plan name. The valid values are “Alphex”, “alphex”, “Glamron”, “glamron”, “User”, or “user”.
[4 pts] If the user enters something else for the plan name, print out an error message to the console (“Invalid plan. Exiting the program.”) and exit the program.
Assign values for premium, deductible, and coinsurance.
§ [3 pts] If “Alphex” or “Glamron” (or either lower-case version) was selected, set premium, deductible, and coinsurance from the other variables in your program.
§ [12 pts] If the “User” (or “user”) plan was selected, solicit the three attributes using three JOptionPane input dialogs, storing the values in premium, deductible, and coinsurance. You should accept coinsurance as a fractional value. For example, if the user enters “0.2”, that represents 20% coinsurance.
Note that at this point in your program, premium, deductible, and coinsurance should have the proper values, regardless of which plan was selected. This is a step toward modularity, an important principle in computer science: the rest of the program does not need to know what plan was selected; it can proceed by using those three variables alone.
[6 pts] Solicit the amount of medical bills from the user via the console, using the message “Enter the amount of medical bills: “
[15 pts] Calculate the health care costs (premium + amount toward deductible + any coinsurance costs). You should use an if statement to check if the bills are more than the deductible.
[8 pts] Display the results to the console. The message should include the premium, the other costs, and the total, formatted like Premium: $5000.00 Other costs: $428.20 Total costs: $5428.20
[4 pts] Note that all of the dollar amounts should be rounded to the nearest cent, and all amounts should display two digits on the right of the decimal point. All of the calculations in your program should support cents, but do not round until the final output. You can use System.out.printf to format your results.
Testing
I recommend testing your program on a variety of cases. You should at least ensure that you test enough that every line of code in your program has been executed by at least one test case. You can use the examples in the first section of these instructions as a starting point. The best advice for testing your program is to think of things that might break it. These are often weird edge cases, like 0% coinsurance or 100% coinsurance, deductibles that are very small (e.g., 0.01), or medical bills that are very high.
You can assume that your program will be given correctly-formatted dollar and cent amounts when prompted. For example, we will not evaluate your program by entering “WAY TOO HIGH” for the premium. While these are things that real software needs to check, that is beyond the scope of this project. You do need to check that the health plan name is one of the allowed values, however.