Create a JavaFx application which implement different mathematical operation as indicated: GUI Calculator Enter first number (x): Enter second number (y): Output: Calculate GUI Calculator 0 X Reset GUI Calculator Enter first number (x) Enter second number (y): Output GUI Calculator 1 Calculate Reset

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

below is my code, need help with this javafx code

 

package com.example.demo1;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Objects;
import java.util.Optional;

public class HelloApplication extends Application {
public boolean inputValidation(String s){
try {
int a = Integer.parseInt(s);
return true;
}catch (Exception e ){

return false;
}


}
@Override
public void start(Stage stage) throws IOException {
GridPane grid= new GridPane();
grid.setVgap(10);
grid.setHgap(10);
//Component
RadioButton opt1 = new RadioButton("*");
RadioButton opt2 = new RadioButton("+");
RadioButton opt3 = new RadioButton("-");
RadioButton opt4 = new RadioButton("/");
Label weightL = new Label("Enter first number(x)");
Label heightL = new Label("Enter second number(y)");
Label bmiL = new Label("GUI");
TextField hText = new TextField();
TextField wText = new TextField();
TextField bText = new TextField();
Button btn = new Button("Calculate!");
HBox toggle = new HBox();

ToggleGroup tg = new ToggleGroup();
opt1.setToggleGroup(tg);
opt2.setToggleGroup(tg);
opt3.setToggleGroup(tg);
opt4.setToggleGroup(tg);
toggle.getChildren().addAll(opt1,opt2,opt3,opt4);
grid.add(weightL,0,0);
grid.add(wText,1,0);
grid.add(heightL,0,1);
grid.add(hText,1,1);
grid.add(toggle,0,2);
grid.add(btn,0,3);
grid.add(bmiL,0,4);
grid.add(bText,1,4);

btn.setOnAction(event -> {
if(inputValidation(hText.getText())&&inputValidation(wText.getText())) {
RadioButton gg = (RadioButton) tg.getSelectedToggle();
if (gg == null) {
Alert a = new Alert(Alert.AlertType.ERROR);
a.setTitle("Error");
a.setHeaderText("Nothing is Selected");
a.setContentText("Please select the option out of English or Metric");

a.show();
} else {
double weight = Double.parseDouble(wText.getText());
double height = Double.parseDouble(hText.getText());
if (gg.getText() == "*") {

double BMI = (weight / Math.pow(height,2)) * 703;
bText.setText(Double.toString(BMI));

} else if (gg.getText() == "+") {
double BMI = ((weight) / Math.pow(height,2))*10000;
bText.setText(Double.toString(BMI));
}

}
}else {
Alert a = new Alert(Alert.AlertType.ERROR);
a.setTitle("Error");
a.setHeaderText("Invalid Input");
a.setContentText("Please check Your input maybe br it is invalid");

a.show();
}
});
Scene scene = new Scene(grid);
stage.setWidth(400);
stage.setHeight(400);
stage.setTitle("BMI Calculator");
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch();
}
}

Create a JavaFx application which implement different mathematical operation as indicated:
GUI Calculator
Enter first number (x):
Enter second number (y):
Output:
Calculate
GUI Calculator
X
Reset
GUI Calculator
Enter first number (x):
Enter second number (y)
Output
W
GUI Calculator
Calculate
Reset
*** Make sure to apply any necessary validation you see fit for this application to avoid crashing your
application
*** you may use a label to show the output instead of TextField.
*** validation messages may indicated on the window (stage) or pop out as an Alert()
You may use any layout see fit.
Transcribed Image Text:Create a JavaFx application which implement different mathematical operation as indicated: GUI Calculator Enter first number (x): Enter second number (y): Output: Calculate GUI Calculator X Reset GUI Calculator Enter first number (x): Enter second number (y) Output W GUI Calculator Calculate Reset *** Make sure to apply any necessary validation you see fit for this application to avoid crashing your application *** you may use a label to show the output instead of TextField. *** validation messages may indicated on the window (stage) or pop out as an Alert() You may use any layout see fit.
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY