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.