This program must be in java. Design and code a program that will process insura
ID: 3666764 • Letter: T
Question
This program must be in java.
Design and code a program that will process insurance premiums for one insurance cycle. Customer profiles will be used to calculate the premiums. A customer’s profile will be read from the text file PolicyInformation.txt
Apply the divide and conquer approach to the project to break the problem it solves into smaller problems. Write the following static methods to solve each of the smaller problems.
Methods (in addition to main):*
A method that calculates and returns the final price of a single customer’s insurance premium. Calculate the premium using the table on page 2.
A method that calculates and returns a customer's BMI.
A method that will calculate and return the total price of all insurance premiums.
A method that displays the policy information as shown in the sample output on page 3 of this document.
Process the PolicyInformation.txt file in such a way that it can handle a similarly formatted file that contains any number of customers.
The text file contains policy information in the following order:
Policy Number
Provider Name
Policyholder First Name
Policyholder Last Name
Age
Smoking Status
Height in inches
Weight
Please note: The PolicyInformation.txt file should not be edited. Your program should be able to process the text file as is.
Display the total number of premiums processed in the cycle. See sample output on page 3 of this document.
NOTE: If your Java program tries to read a file that is not accessible, an error occurs. Java calls errors like these Exceptions. If a method might potentially cause an error to occur, Java requires that you handle that error in case it should happen. You will learn how to do handle exceptions if you take CSC251. For now, it is sufficient to state the error might occur. You will need to do this for your main method and any other method that uses code that reads from a file. To prevent a syntax error, add "throws FileNotFoundException" to the method header. For the main method, your code should be: public static void main (String [] args) throws FileNotFoundException
Premium Table
Base rate
$400
Over 50
Add $100
Smoker
Add $150
BMI over 40
Add $100
A bmi is calculated as weight times 703 divided by height2.
This is the information from the txt file:
3450
State Farm
Alice
Jones
20
smoker
65
110
3455
Aetna
Bob
Lee
54
non-smoker
72
200
2450
Met Life
Chester
Williams
40
smoker
71
300
3670
Global
Cindy
Smith
55
non-smoker
62
140
1490
Reliable
Jenna
Lewis
30
smoker
60
105
3477
State Farm
Craig
Duncan
23
smoker
68
215
Base rate
$400
Over 50
Add $100
Smoker
Add $150
BMI over 40
Add $100
A bmi is calculated as weight times 703 divided by height2.
Explanation / Answer
public class Premium
{
private int a;
private int h;
private int w;
private String s;
int i;
public void setAge(int age)
{
a = age;
}
public void setHeight(int height)
{
h = height;
}
public void setWeight(int weight)
{
w= weight;
}
public void setSmoke(String smoker)
{
s = smoker;
}
public int getHeight()
{
return h;
}
public int getWeight()
{
return w;
}
public int getAge()
{
return a;
}
public String getSmoke()
{
return s;
}
public Premium(int age, int height, int weight, String smoker)
{
a = age;
h = height;
w = weight;
s = smoker;
}
public static int calculateInsurance(int age, String smoker)
{
String smoking = "smoker";
int insurance;
final int insuranceBase = 400;
BMI custBMI = new BMI();
double bmi= custBMI.calculateBMI();
if (age > 50)
{
insurance = insuranceBase + 100;
}
else
{
insurance = insuranceBase;
}
if (smoker.equals('Y'))
{
insurance += 150;
}else {
insurance +=0;
}
if (bmi > 40)
{
insurance += 100;
}
else
{
insurance +=0;
}
return insurance;
}
public void setInsurance(int insurance)
{
i = insurance;
}
public int getInsurance()
{
return i;
}
public void displayPrice()
{
System.out.println("Insurance Premium Cost: " + getInsurance());
}
}
public class BMI
{
private int h;
private int w;
public void setWeight(int weight)
{
w= weight;
}
public void setHeight(int height)
{
h = height;
}
public int getWeight()
{
return w;
}
public int getHeight()
{
return h;
}
public double calculateBMI()
{
double bmi;
bmi = (getWeight() * 703)/(getHeight() * getHeight());
return bmi;
}
}
import javax.swing.JOptionPane;
public class Insurance
{
public static void main(String[] args)
{
String submit;
System.out.println("Please fill the information to get an insurance premium.");
System.out.println();
do
{
String input;
String fname;
String lname;
int age;
String smoker;
int height;
int weight;
fname =JOptionPane.showInputDialog("Enter your first name: ");
lname =JOptionPane.showInputDialog("Enter your last name: ");
input = JOptionPane.showInputDialog("Enter your age: ");
age = Integer.parseInt(input);
while (age < 0 || age > 141)
{
input = JOptionPane.showInputDialog("Invalid input! Age must be 1 through 140. Please enter your age: ");
age = Integer.parseInt(input);
}
smoker = JOptionPane.showInputDialog("Are you a smoker? Please enter Y or N: ");
if (!smoker.equalsIgnoreCase("Y"))
{
System.out.println("");
}
else if (!smoker.equalsIgnoreCase("N"))
{
smoker = JOptionPane.showInputDialog("Invalid input! Are you a smoker? Answer must be Y or N: ");
} else
{
System.out.println("");
}
input = JOptionPane.showInputDialog("Please enter your height in inches: ");
height = Integer.parseInt(input);
while (height < 0 || height > 108)
{
input = JOptionPane.showInputDialog("Invalid input! Height must be between 1 and 108 inches. Please enter your height in inches: ");
height = Integer.parseInt(input);
}
input = JOptionPane.showInputDialog("Please enter your weight in pounds: ");
weight= Integer.parseInt(input);
while (weight < 0 || weight > 800)
{
input = JOptionPane.showInputDialog("Invalid input! Weight must be between 1 and 800 pounds. Please enter your weight in pounds: ");
weight = Integer.parseInt(input);
}
Premium customer = new Premium(age, height, weight, smoker);
displayResults(fname, lname, age, smoker, height, weight);
customer.displayPrice();
submit =JOptionPane.showInputDialog("Would you like to submit another profile? Enter Y or N: ");
if (!submit.equalsIgnoreCase("Y"))
{
System.out.println("");
}
else if (!smoker.equalsIgnoreCase("N"))
{
submit = JOptionPane.showInputDialog("Invalid input!Another profile? Answer must be Y or N: ");
}
else
{
System.out.println("");
}
}
while (submit.equalsIgnoreCase("Y"));
}
public static void displayResults(String fname, String lname, int age, String smoker, int height, int weight)
{
System.out.println(" ");
System.out.println("First Name: " + fname);
System.out.println("Last Name: " + lname);
System.out.println("Age: " + age);
System.out.println("Smoking Status: " + smoker);
System.out.println("Height(in.): " + height);
System.out.println("Weight(lbs): " + weight);
System.out.println(" ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.