-1

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.

krissy
  • 1
  • 3

1 Answers1

0

I think I see your problem. This is the code that you have now:

if (numOutlets>=2 || numZones>=5)
        installationType = "Custom";
else
        installationType = "Standard";

This is what you need to change it to:

if (numZones>=2 || numOutlets>=5)
        installationType = "Custom";
else
        installationType = "Standard";

It appears based on the above code you had the variables switched.

Vale Tolpegin
  • 77
  • 1
  • 9
  • I just tried that then, i think it is something to do with the "installationType". It says that is cannot resolve the symbol Thanks though :) – krissy Aug 31 '15 at 12:02
  • Can you copy and paste the entire Java exception? I see numerous places that could be causing your problem, but I need to see exactly what is breaking. Thanks! – Vale Tolpegin Aug 31 '15 at 12:06
  • Error:(179, 13) java: cannot find symbol symbol: variable installationType location: class Main Error:(181, 13) java: cannot find symbol symbol: variable installationType location: class Main Error:(183, 29) java: cannot find symbol symbol: variable InstallationType location: class Main Error:(183, 9) java: cannot find symbol symbol: variable installType location: class Main – krissy Aug 31 '15 at 12:07
  • Is there something i need to do to be able to get the "installationType" variable from my other class? – krissy Aug 31 '15 at 12:09
  • Where are you declaring installationType relative to the enterButtonClicked() method ( same class, parent class, etc )? Also, this code: installType.setText(InstallationType + ""); needs to be replaced with installType.setText(installationType + "");. You have a capitalization error that breaks the build. – Vale Tolpegin Aug 31 '15 at 12:18
  • I am not quite sure how to do that, i am sorry i am still getting into java. I only know bits and pieces of it so i get stuck easy. – krissy Aug 31 '15 at 12:23
  • No problem! I now see that the problem is that you are declaring the variable in the wrong place. Since the installationType variable is located within a separate class from the enterButtonClicked() method, it cannot be referenced by name. You will need to create a variable in the enterButtonClicked() method, or create a getter and setter method for the installationType variable in the Installation class ( see [link](http://stackoverflow.com/questions/2036970/how-do-getters-and-setters-work) ) – Vale Tolpegin Aug 31 '15 at 20:11
  • Sorry for the late reply, I just got a chance to check back here. No problem! I'm glad it works! – Vale Tolpegin Sep 02 '15 at 22:40