예제 #1
0
  private void addToBasketActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addToBasketActionPerformed
    // Adds the selected valid pipe to the arraylist.
    int inQuantity = 0;
    boolean quantityVal = false;
    pipesInfoOutput.setText("");

    // If a valid pipe is found
    if (findValidPipe() == true) {

      // Validates the quantity input.
      try {
        inQuantity = Integer.parseInt(quantityTF.getText());
        if (inQuantity < 1.0 || inQuantity > 20.0) {
          pipesInfoOutput.setText("");
          validationMessages("Quantity", 1.0, 20.0);
        } else {
          quantityVal = true;
        }
      } catch (NumberFormatException e) {
        System.err.println(e);
        pipesInfoOutput.setText("");
        validationMessages("QuantityR", 0, 0);
      }

      /* Adds the valid pipe to an arraylist a set amount of times as
      defined by the quantity variable */
      if (quantityVal == true) {

        for (int x = 0; x < inQuantity; x++) {
          // Checks that the basket is not full
          if (Inventory.size() < 50) {
            Inventory.add(pipe);
          } else {
            pipesInfoOutput.setText(
                "Error Add to Basket: "
                    + "Basket Full."
                    + "\nQuantiy of Pipes in Basket: "
                    + Inventory.size());
          }
        }
        ;

        updateTable();
      }
    }
  } // GEN-LAST:event_addToBasketActionPerformed
예제 #2
0
  // ----------------------------------------------------------------------
  private boolean findValidPipe() {
    Pipes tempPipe = new TypeZero();
    double inLength = 0.0, inDiameter = 0.0;
    String selectedGrade, selectedColour;
    int inGrade, inColour;
    boolean inInsul, inReinforce, inChem, lengthVal = false, diameterVal = false;

    pipesInfoOutput.setText("");
    boolean pipeVal = false;

    try {
      inLength = Double.parseDouble(lengthTF.getText());
      if (inLength < 0.1 || inLength > 6.0) {
        // ERROR MESSAGES
        validationMessages("Length", 0.1, 6.0);
        lengthTF.setText("");
      } else {
        lengthVal = true;
      }
    } catch (NumberFormatException e) {
      System.err.println(e);
      validationMessages("LengthR", 0, 0);
      lengthTF.setText("");
    }

    try {
      inDiameter = Double.parseDouble(diameterTF.getText());
      if (inDiameter < 1.0 || inDiameter > 35.0) {
        // ERROR MESSAGES
        validationMessages("Diameter", 1.0, 35.0);
        diameterTF.setText("");
      } else {
        diameterVal = true;
      }
    } catch (NumberFormatException e) {
      System.err.println(e);
      validationMessages("DiameterR", 0, 0);
      diameterTF.setText("");
    }

    selectedGrade = gradeCB.getSelectedItem().toString();
    inGrade = Integer.parseInt(selectedGrade);

    selectedColour = colourCB.getSelectedItem().toString();
    if ("None".equals(selectedColour)) {
      inColour = 0;
    } else {
      inColour = Integer.parseInt(selectedColour);
    }

    inInsul = insulCheck.isSelected();

    inReinforce = reinforceCheck.isSelected();

    inChem = chemCheck.isSelected();

    if (lengthVal == true && diameterVal == true) {
      pipe =
          tempPipe.selectPipe(
              inLength, inDiameter, inGrade, inColour, inInsul, inReinforce, inChem);

      if (pipe.getPipeType() == "") {
        pipesInfoOutput.setText("Error: No pipe found in that " + "configuration.");
        pipesInfoOutput.append("\nPlease try a different " + "configuration.");
      } else {
        pipeVal = true;
        getPipeInfo();
      }
    }
    return pipeVal;
  }