Question

In: Computer Science

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 PPO costs $600 per month, the dental coverage adds $75 per month, and the vision care adds $20 per month. Save the project as FXInsurance.

Solutions

Expert Solution

//Java code

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.text.DecimalFormat;

public class FXInsurance extends Application {
    /**
     *  HMO costs $200 per month, the PPO costs $600 per month, the dental
     *  coverage adds $75 per month, and the vision care adds $20 per month.
     */
    //constants
    private final double HMO = 200,PPO=600;
    private final double DENTAL_COVERAGE = 75;
    private final double VISION_CARE = 20;
    @Override
    public void start(Stage primaryStage) throws Exception {
        HBox box1 = new HBox();
        box1.setPadding(new Insets(10,10,10,10));
        HBox box2 = new HBox();
        box2.setPadding(new Insets(10,10,10,10));
        box2.setSpacing(10);
        box1.setSpacing(10);
        //Radio Buttons
        RadioButton rdbHMO = new RadioButton("HMO");
        RadioButton rdbPPO = new RadioButton("PPO");
        ToggleGroup group = new ToggleGroup();
        rdbHMO.setToggleGroup(group);
        rdbPPO.setToggleGroup(group);
        box1.getChildren().add(rdbHMO);
        box1.getChildren().add(rdbPPO);
        
        //CheckBoxes
        CheckBox chkDentalInsurance = new CheckBox("Dental Insurance");
        CheckBox chkVisionInsurance = new CheckBox("Vision Insurance");
        box2.getChildren().add(chkDentalInsurance);
        box2.getChildren().add(chkVisionInsurance);
        HBox box3 = new HBox();
        box3.setPadding(new Insets(10,10,10,10));
        
        //textArea
        TextArea txtResult = new TextArea();
        txtResult.setEditable(false);
        txtResult.setPrefColumnCount(300);
        txtResult.setPrefRowCount(400);
        
        //Button
        box3.getChildren().add(txtResult);
        HBox box4 = new HBox();
        box4.setPadding(new Insets(10,10,10,10));
        Button btnCalculate = new Button("Display");
        box4.getChildren().add(btnCalculate);
        
        
        VBox vBox = new VBox();
        vBox.setPadding(new Insets(10,10,10,10));
        vBox.getChildren().add(box1);
        vBox.getChildren().add(box2);
        vBox.getChildren().add(box3);
        vBox.getChildren().add(box4);

        //Scene
        Scene scene = new Scene(vBox,350,250);
        primaryStage.setScene(scene);
        primaryStage.setTitle("FXInsurance");
        primaryStage.show();

        //button listener
        btnCalculate.setOnAction(new EventHandler() {
            double price ;
            String result ;
            @Override
            public void handle(ActionEvent event) {
                result="";
                price =0;
                if(rdbHMO.isSelected())
                {
                    result +="Insurance: health maintenance organization, ";
                    price+= HMO;
                }
                if(rdbPPO.isSelected())
                {
                    result+="Insurance : preferred provider organization,";
                    price+=PPO;
                }
                if(chkDentalInsurance.isSelected())
                {
                    result+="\ndental insurance, ";
                    price+=DENTAL_COVERAGE;
                }
                if(chkVisionInsurance.isSelected())
                {
                    result+="\nvision insurance, ";
                    price+=VISION_CARE;
                }

                txtResult.setText(result+"\nInsurance Price: "+ DecimalFormat.getCurrencyInstance().format(price));
            }
        });
    }
    public static void main(String[] args)
    {
        launch(args);
    }
}

//Output


Related Solutions

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...
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is...
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is determined by a mouse drag. Use the initial mouse press location as the fixed center point of the circle. Compute the distance between the current location of the mouse pointer and the center point to determine the current radius of the circle.
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
(Not in Swing) Write a JavaFX application that creates polyline shapes dynamically using mouse clicks. Each...
(Not in Swing) Write a JavaFX application that creates polyline shapes dynamically using mouse clicks. Each mouse click adds a new line segment to the current polyline from the previous point to the current mouse position. Allow the user to end the current polyline with the double click. Also, provide a button that clears the window and allows the user to begin again.
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first...
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
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...
Write a JavaFX application that presents two buttons and a number (initially 50) to the user....
Write a JavaFX application that presents two buttons and a number (initially 50) to the user. Label the buttons Increment and Decrement. When the increment button is pushed, increment the displayed value. Likewise, decrement the value when the decrement button is pushed. This has to use Java.Fx and not Java.Awt
Java Write a JavaFX application that displays a button and a number. Every time the button...
Java Write a JavaFX application that displays a button and a number. Every time the button is pushed, change the number to a random value between 1 and 100. Thank you and can you show a picture of the result as well
Write a JavaFX application that displays a Label containing the opening sentence or two from your...
Write a JavaFX application that displays a Label containing the opening sentence or two from your favorite book. Save the project as FXBookQuote1a. Add a button to the frame in the FXBookQuote program. When the user clicks the button, display the title of the book that contains the quote in a second label. Save the project as FXBookQuote1b // FXBookQuote1a.java import javafx.application.Application; import static javafx.application.Application.launch; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.scene.text.Font; import javafx.stage.Stage; public class FXBookQuote1a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT