85.5k views
5 votes
ST 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 The example run below shows how the program would run. Note, user input is denoted in orange. Example run #1 What type of insurance do you need? Apartment Would you like premium protection? yes The Apartment insurance you selected costs $475.00. Example run #2 What type of insurance do you need? Auto The Auto insurance you selected costs $200.00. Example run #3 What type of insurance do you n

User Miguelina
by
4.1k points

1 Answer

4 votes

Answer:

package form;

import javax.swing.JOptionPane;

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"+

"\\1. Apartment"+

"\\2. Auto"+

"\\3. 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;

}

}

}

}

Explanation:

  • Check if policy is not null, then add 300 to the totalCost variable.
  • Check if the val variable is equal to 0, then add 175 to the totalCost variable.
User Thong Nguyen
by
4.5k points