its a JavaFX project Create a working order form for Orinoco as shown. Sales tax is 7%. To display the Total Due (a Label) as currency, research how to use class NumberFormat. package application;
its a JavaFX project
Create a working order form for Orinoco as shown. Sales tax is 7%.
To display the Total Due (a Label) as currency, research how to use class NumberFormat.
package application;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
public class Main extends Application {
TextField itemField,quantityField,priceField;
Label totalValue;
CheckBox isTaxable;
ToggleGroup shipping;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("orinoco.com");
GridPane rootNode = new GridPane();
rootNode.setPadding(new Insets(25));
rootNode.setHgap(10);
rootNode.setVgap(10);
Scene scene = new Scene(rootNode);
//create labels for order
rootNode.add(new Label("Item"),0,0);
itemField=new TextField();
rootNode.add(itemField,1,0);
rootNode.add(new Label("Price"),0,1);
priceField = new TextField();
rootNode.add(priceField,1,1);
rootNode.add(new Label("Quantity"),0,2);
quantityField = new TextField();
rootNode.add(quantityField,1,2);
isTaxable = new CheckBox("Taxable?");
rootNode.add(isTaxable,1,3);
rootNode.add(new Label("Shipping"),0,4);
//create toggle group
shipping=new ToggleGroup();
//create radiobuttons for shipping time
RadioButton r1 = new RadioButton("$20");
RadioButton r2 = new RadioButton("$12");
RadioButton r3 = new RadioButton("$5");
r1.setToggleGroup(shipping);
r2.setToggleGroup(shipping);
r3.setToggleGroup(shipping);
rootNode.add(new Label("Next Day"),0,5);
rootNode.add(r1,1,5);
rootNode.add(new Label("This Week"),0,6);
rootNode.add(r2,1,6);
rootNode.add(new Label("Some Day"),0,7);
rootNode.add(r3,1,7);
totalValue = new Label();
rootNode.add(new Label("Total Due"),0,8);
rootNode.add(totalValue,1,8);
Button processButton = new Button("Process");
rootNode.add(processButton,0,9);
processButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
calculateAndSetValues();
}
});
Button resetButton = new Button("Reset");
rootNode.add(resetButton,1,9);
resetButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
itemField.setText("");
quantityField.setText("");
priceField.setText("");
isTaxable.setSelected(false);
shipping.selectToggle(null);
totalValue.setText("");
}
});
primaryStage.setScene(scene);
primaryStage.show();
}
private void calculateAndSetValues() {
double quantity = Double.parseDouble(quantityField.getText());
double price = Double.parseDouble(priceField.getText());
double amount = quantity * price;
if(isTaxable.isSelected()) {
amount+=amount*0.07;
}
RadioButton rb = (RadioButton)shipping.getSelectedToggle();
amount+=Double.parseDouble(rb.getText().substring(1));
totalValue.setText("$"+String.format("%2f",amount));
}
public static void main(String[] args) {
launch(args);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images