In: Computer Science
Note: For input/output, you must use the JOptionPane class.
IST Insurance Brokers, Inc. needs your help to create a program to calculate the total cost of insurance policies issued by its brokers. Write a small Java program that prompts the user for a type of insurance policy and then determines the total policy cost.
The company currently supports only three types of insurance policies: Apartment, Auto, and Condo. When a user enters a different type of insurance policy, they should be told the program does not support that type of insurance policy at this time.
Use the information below to determine total policy cost:
Apartment - Has a base cost of $300.00 with the option to
purchase premium protection for an additional $175.00
Auto - Has a base cost of $200.00
Condo - Has a base cost of $300.00 with the option to purchase
premium protection for an additional $175.00
package form;
import javax.swing.JOptionPane; // Needed for Dialog Box
/**
* This program demonstrates
* showInputDialog.
*/
public class ISTInsuranceBrokers
{
public static void main(String[] args)
{
while(true){
String policy;
double totalCost=0;
String options = "Please enter anyone of the below policy type"+
"\n1. Apartment"+
"\n2. Auto"+
"\n3. Condo";
policy = JOptionPane.showInputDialog(options);
if(policy!=null){
if(policy.equalsIgnoreCase("Apartment") || policy.equalsIgnoreCase("Condo")){
totalCost+=300;
int val = JOptionPane.showConfirmDialog(null,
"Would you like to purchase premium protection for an additional $175.00",
"Addional info!!!",
JOptionPane.YES_NO_OPTION);
if(val==0){
totalCost+=175;
}
}else if(policy.equalsIgnoreCase("Auto")){
totalCost+=200;
}else{
int val = JOptionPane.showConfirmDialog(null,
"the program does not support that type of insurance policy at this time. Would you like to buy other policy?",
"Buy Confirmation!!!",
JOptionPane.YES_NO_OPTION);
if(val!=0){
System.exit(0);
}
if(val==0){
continue;
}
}
int val = JOptionPane.showConfirmDialog(null,
"Policy cost is : $"+totalCost*1.00+". Click yes to buy",
"Buy Confirmation!!!",
JOptionPane.YES_NO_OPTION);
if(val==0){
totalCost+=175;
break;
}
}else{
break;
}
}
}
}
output: