Hey guys I am making a java application to book installation. I am trying to set up an If else statement to make the InstallType column print out either "Standard" or "Custom" The way it needs to do this is: if the numOutlets variable is greater than 4 OR is numZones is greater than 2 then is should print out Custom. If the number of either numOutlets is lower or equal to 4 or the number in numZones is equal to or less than 2 it should print out "Standard".
I am trying to make it do this on the enterButton:
public void enterButtonClicked(){
Installation installation = new Installation();
installation.setCustomerName(nameInput.getText());
installation.setHouseNumber(Double.parseDouble(houseInput.getText()));
installation.setStreetName(streetInput.getText());
installation.setTown(townInput.getText());
installation.setNumOutlets(Integer.parseInt(outletInput.getText()));
installation.setNumZones(Integer.parseInt(zoneInput.getText()));
installationTable.getItems().add(installation);
double numOutlets = Double.parseDouble(outletInput.getText());
double numZones = Double.parseDouble(zoneInput.getText());
if (numOutlets>=2 || numZones>=5)
installationType = "Custom";
else
installationType = "Standard";
installType.setText(InstallationType + "");
nameInput.clear();
houseInput.clear();
streetInput.clear();
townInput.clear();
outletInput.clear();
zoneInput.clear();
}
This is my TableView
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("CQ Air-Conditioning");
//installationID
TableColumn<Installation, Integer> installationID = new TableColumn<>("Installation ID");
installationID.setMinWidth(100);
installationID.setCellValueFactory(new PropertyValueFactory<>("installationNumber"));
//CustomerName
TableColumn<Installation, String> nameColumn = new TableColumn<>("Name");
nameColumn.setMinWidth(200);
nameColumn.setCellValueFactory(new PropertyValueFactory<>("customerName"));
//House Number
TableColumn<Installation, Double> houseNo = new TableColumn<>("House Number");
houseNo.setMinWidth(100);
houseNo.setCellValueFactory(new PropertyValueFactory<>("houseNumber"));
//Street Name
TableColumn<Installation, String> street = new TableColumn<>("Street Name");
street.setMinWidth(200);
street.setCellValueFactory(new PropertyValueFactory<>("streetName"));
//Town Name
TableColumn<Installation, String> Town = new TableColumn<>("Town Name");
Town.setMinWidth(200);
Town.setCellValueFactory(new PropertyValueFactory<>("town"));
//number outlets
TableColumn<Installation, Double> numberOutlets = new TableColumn<>("Outlets");
numberOutlets.setMinWidth(50);
numberOutlets.setCellValueFactory(new PropertyValueFactory<>("numOutlets"));
//number Zones
TableColumn<Installation, Double> numberZones = new TableColumn<>("Zones");
numberZones.setMinWidth(50);
numberZones.setCellValueFactory(new PropertyValueFactory<>("numZones"));
//Installation Type
TableColumn<Installation, String> installType = new TableColumn<>("Type of Installation");
installType.setMinWidth(200);
installType.setCellValueFactory(new PropertyValueFactory<>("installationType"));
//total cost
TableColumn<Installation, Double> cost = new TableColumn<>("Total Cost");
cost.setMinWidth(150);
cost.setCellValueFactory(new PropertyValueFactory<>("totalCost"));
//nameInput
nameInput = new TextField();
nameInput.setPromptText("Enter Name");
nameInput.setMinWidth(100);
//houseInput
houseInput = new TextField();
houseInput.setPromptText("enter house number");
//streetInput
streetInput = new TextField();
streetInput.setPromptText("enter street Name");
//town input
townInput = new TextField();
townInput.setPromptText("enter town");
//outlets input
outletInput = new TextField();
outletInput.setPromptText("enter number of outlets");
//zones input
zoneInput = new TextField();
zoneInput.setPromptText("enter number of zones");
//buttons
Button enterButton = new Button ("Enter");
enterButton.setOnAction(e -> enterButtonClicked());
enterButton.setMinWidth(200);
Button clearButton = new Button ("Clear");
clearButton.setOnAction(e -> clearButtonClicked());
clearButton.setMinWidth(50);
Button deleteButton = new Button ("Delete");
deleteButton.setOnAction(e -> deleteButtonClicked());
deleteButton.setMinWidth(50);
Button exitButton = new Button ("Exit");
exitButton.setOnAction(e -> exitButtonClicked());
exitButton.setMinWidth(50);
HBox hbox = new HBox();
hbox.setPadding(new Insets(25, 10, 50, 10));
hbox.setSpacing(10);
hbox.getChildren().addAll(nameInput, houseInput, streetInput, townInput, outletInput, zoneInput);
HBox buttons = new HBox();
buttons.setPadding(new Insets(10,10,10,10));
buttons.setSpacing(15);
buttons.setAlignment(Pos.CENTER);
buttons.getChildren().addAll(clearButton, enterButton, deleteButton, exitButton);
installationTable = new TableView<>();
installationTable.setItems(getInstallation());
installationTable.getColumns().addAll(installationID, nameColumn, houseNo, street, Town, numberOutlets, numberZones, installType, cost);
VBox vbox = new VBox();
vbox.getChildren().addAll(hbox,installationTable, buttons);
Scene scene = new Scene(vbox);
window.setScene(scene);
window.show();
}
I am using a "Main" class and a class called "Installation" with my variables and getters and setters.
This is my variables in the "Installation" Class
private String customerName;
private String streetName;
private String town;
private String installationType;
private double postCode;
private double houseNumber;
private int numZones;
private int numOutlets;
private double totalCost;
private double standardCost = 7200;
private double customCost;
private int installationNumber = 0;
Thank you to anybody that helps me, i have been trying at this for ages and cant quite seem to get it. Thanks so much! sorry if i am not posting correctly, still trying to learn.
Aucun commentaire:
Enregistrer un commentaire