Tip Calculator Programming Assignment For this assignment you are going to program a JavaFX tip calculator app like you might find on your phone. The interface is shown below. To use the app the user...

1 answer below »
Program, Java, Code needed.


Tip Calculator Programming Assignment For this assignment you are going to program a JavaFX tip calculator app like you might find on your phone. The interface is shown below. To use the app the user types in the check amount. The user then chooses a tip percent using a slider. The user can elect to split the total by up to 5 people by making a selection from the Split choice box. Press the calculate tip button to calculate the tip. Your application should display the tip amount, the total bill, and the amount per person. Use a grid layout pane for your application. The title and calculate tip button should span 2 columns. Note that all text is right-justified. You should choose a font other than the default font for the application. The title should be in a second, larger font. The tip percent label should reflect the value of the slider. All output values should be formatted as currency. The user should not be allowed to edit or change the tip amount, the total and the amount per person. The default value for the tip percent should be set at 15%. The default value of the Split choice box should be set to “1 way”. Sample run: When the user clicks in the check amount text field your program should reset the application to its default state so that the user can enter a new check amount. To do this, all text fields should be cleared, the tip percent should be set to 15% and the split choice box should be set to read “1 Way”.
Answered Same DayDec 04, 2021

Answer To: Tip Calculator Programming Assignment For this assignment you are going to program a JavaFX tip...

Shweta answered on Dec 06 2021
140 Votes
Solution72317/TipCalculator.java
Solution72317/TipCalculator.java
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
im
port javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.control.TextFormatter.Change;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
/**
 *
 * @author Acer
 */
public class TipCalculator extends Application {
    @Override
    public void start(Stage stage) {

           //Create a patter for check amount text box, a)Upto 2 decimal b) only numeric value not string
        Pattern decimalPattern = Pattern.compile("-?\\d*(\\.\\d{0,2})?");
        UnaryOperator filter = c -> {
            if (decimalPattern.matcher(c.getControlNewText()).matches()) {
                return c;
            } else {
                return null;
            }
        };
       //Create formater with filter of string and decimal value upto 2 place
        TextFormatter formatter = new TextFormatter<>(filter);

            //Create Slider with min 0, max 25 and default value to 15
        Slider sliderTipPercent = new Slider(0, 25, 15);
        sliderTipPercent.setShowTickMarks(true);
        sliderTipPercent.setStyle("-fx-font: 18px \"Time New Roman\";");
        sliderTipPercent.setShowTickLabels(true);
        sliderTipPercent.setShowTickMarks(true);
        sliderTipPercent.setSnapToTicks(true);
        sliderTipPercent.setMinorTickCount(5);
        // sets the value of the property blockIncrement 
        sliderTipPercent.setBlockIncrement(5);

        //Text for Heading
        Text txtHeading = new Text("Tip Calculator");
        txtHeading.setFont(Font.font("Time New Roman", FontWeight.LIGHT,25 ));
        //Text Check Amount
        Text txtCheckAmount = new Text("Check Amount: ");
        txtCheckAmount.setFont(Font.font("Time New Roman", FontWeight.LIGHT, 18));

        //Text for TipPercent,which randomly change the percent value by slider
        Text txtTipPercent = new Text();
        txtTipPercent.setFont(Font.font("Time New Roman", FontWeight.LIGHT, 18));
        txtTipPercent.textProperty().bind(
                sliderTipPercent.valueProperty().asString("Tip Percent: %1.0f%" + "%")
        );
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here