Question

In: Computer Science

Java 14-8 Finish the JInsurance application that allows the user to choose insurance options in JCheckBoxes....

Java 14-8

Finish the JInsurance application that allows the user to choose insurance options in JCheckBoxes. Use a ButtonGroup to allow the user to select only one of two insurance types—HMO (health maintenance organization) or PPO (preferred provider organization). Use regular (single) JCheckBoxes for dental insurance and vision insurance options; the user can select one option, both options, or neither option.

As the user selects each option, display its name and price in a text field; the HMO costs $200per month, the PPO costs $600 per month, the dental coverage adds $75 per month, and the vision care adds $20 per month. When a user deselects an item, make the text field blank.

----------------------------------------------------------Code given-----------------------------------------------------

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JInsurance extends JFrame implements ItemListener {
FlowLayout flow = new FlowLayout();
ButtonGroup insGrp = new ButtonGroup();
JCheckBox hmo = new JCheckBox("HMO", false);
JCheckBox ppo = new JCheckBox("PPO", false);
JCheckBox dental = new JCheckBox("Dental", false);
JCheckBox vision = new JCheckBox("Vision", false);
JTextField insChoice = new JTextField(20);
String output, insChosen;
public JInsurance() {
// Write your code here
}
public static void main(String[] arguments) {
JInsurance iFrame = new JInsurance();
iFrame.setSize(400, 100);
iFrame.setVisible(true);
}
@Override
public void itemStateChanged(ItemEvent check) {
// Write your code here
}
}

Solutions

Expert Solution

/*
* Java program that display a gui window that contains
* four check boxes. As user select the check boxes.
* the text boxes will display the price of the service
* */

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JInsurance extends JFrame implements ItemListener
{
   FlowLayout flow = new FlowLayout();
  
   ButtonGroup insGrp = new ButtonGroup();
   JCheckBox hmo = new JCheckBox("HMO", false);
   JCheckBox ppo = new JCheckBox("PPO", false);
  
  
   JCheckBox dental = new JCheckBox("Dental", false);
   JCheckBox vision = new JCheckBox("Vision", false);
  
   JTextField insChoice = new JTextField(20);
   String output, insChosen;
  
   //set contant values
   final int HMO_PRICE = 200;
   final int PPO_PRICE = 600;  
   final int DENTAL_PRICE = 75;
   final int VISION_PRICE = 20;
  
   /*Constructor */
   public JInsurance()
   {
       //set title
       setTitle("INSURANCE");
       //set flow as layout
       setLayout(flow);
      
       //add hmo and ppo to the button group
       insGrp.add(hmo);
       insGrp.add(ppo);
      
       //Add ItemListener to the dental and vision check boxes
       hmo.addItemListener(this);
       ppo.addItemListener(this);
       //Add hmo and ppo to frame
       add(hmo);
       add(ppo);
      
       //Add dental and vision to frame
       add(dental);
       add(vision);
      
       //Add ItemListener to the dental and vision check boxes
       dental.addItemListener(this);
       vision.addItemListener(this);

       //add the text field to the frame
       add(insChoice);
   }
  
  
   public static void main(String[] arguments)
   {
       JInsurance iFrame = new JInsurance();
       iFrame.setSize(400, 100);
       iFrame.setVisible(true);
   }

   /*Implement the itemStateChanged method */
   public void itemStateChanged(ItemEvent check)
   {
       output="";
       //checking if hmi is selected
       if(hmo.isSelected())
           output=String.valueOf("HMO $:"+HMO_PRICE);  
       //checking if ppo is selected
       if(ppo.isSelected())
           output=String.valueOf("PPO $:"+PPO_PRICE);
       //checking if dental is selected
       if(dental.isSelected())
           output+=String.valueOf("Dental $:"+DENTAL_PRICE);  
       //checking if vision is selected
       if(vision.isSelected())
           output+=String.valueOf("Vision $:"+VISION_PRICE);  
       /*Set set output to the insChoice */
       insChoice.setText(output);
   }
}

Sample Output:


Related Solutions

Using NetBeans IDE, write a JavaFX application that allows theuser to choose insurance options. Use...
Using NetBeans IDE, write a JavaFX application that allows the user to choose insurance options. Use a ToggleGroup to allow the user to select only one of two insurance types—HMO (health maintenance organization) or PPO (preferred provider organization). Use CheckBoxes for dental insurance and vision insurance options; the user can select one option, both options, or neither option. As the user selects each option, display its name and price in a text field; the HMO costs $200 per month, the...
Android Studio. Java. Please create an application that -> An activity that allows user to enter...
Android Studio. Java. Please create an application that -> An activity that allows user to enter name, gender, date of birth, state of residence (selected from a pre-defined list: CA, AZ, NV, OR), email address and favorite website. This activity has a button "Show Data" that displays detail entered
write a complete C++ program that allows the user to choose from one of several options....
write a complete C++ program that allows the user to choose from one of several options. The program will display a menu and each option will be in a separate function. The program will continue looping until the user chooses to quit. The module descriptions are given below. a. Prompt for and take as input 3 floating point values (l, w, and h). The program will then calculate the volume (volume = l*h*w ). The program should then output to...
PYTHON (BEGINNER) program that allows the user to choose any of the three sports options described...
PYTHON (BEGINNER) program that allows the user to choose any of the three sports options described below and computes the relevant statistic in each case: Quidditch Score Total: Determined based on the number of goals and whether or not the snitch was caught. A goal is scored by propelling the quaffle through a hoop and each earns the team 10 points. If a team catches the snitch, that team earns an additional 30 points. The snitch can be caught at...
Write an application that allows a user to enter the names and birthdates of up to...
Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names...
Show: Create an application that allows the user to enter the number of calories and fat...
Show: Create an application that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *9 The percentage of...
Create an application that allows the user to place an order at a coffee shop named...
Create an application that allows the user to place an order at a coffee shop named Zips Coffee. Create a coffee order form that looks like a table with columns for coffee type, price and quantity. Provide values for at least three rows of data. Provide a row for the total cost of your order. Create Javascript code to calculate the total of your order and present the total to the user. Provide a button to initiate the Javascript described...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
Java Programming: Write a program that allows the user to compute the power of a number...
Java Programming: Write a program that allows the user to compute the power of a number or the product of two numbers. Your program should prompt the user for the following information: • Type of operation to perform • Two numbers (the arguments) for the operation to perform The program then outputs the following information: • The result of the mathematical operation selected. Menu to be displayed for the user: MATH TOOL 1. Compute the power of a number 2....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT