src/Controller/AddPartController.java
/**
     * *
     * Save Button tests for field/value/data type exceptions, creates
     * in-house/outsourced parts, displays alerts, navigates user back to main
     * screen upon successful part addition.
     */
Save Button tests for field/value/data type exceptions, creates
in-house/outsourced parts, displays alerts, navigates user back to main
screen upon successful part addition.
Save Button tests for field / value / data type exceptions creates in - house / outsourced parts displays alerts navigates user back to main screen upon successful part addition .
@FXML
    private void saveBtnHandler(ActionEvent event) throws IOException {
        String partName = partNameField.getText();
        String inventoryLevel = invLevelField.getText();
        String priceCost = priceCostField.getText();
        String maxInvLevel = maxLevelField.getText();
        String minInvLevel = minLevelField.getText();
        String machIDCompName = dynamicField.getText();
        if (inHousePart == true) {
            partFieldException = Part.inHousePartFieldExceptions(
                    partName,
                    inventoryLevel,
                    priceCost,
                    minInvLevel,
                    maxInvLevel,
                    machIDCompName,
                    partFieldException);
            iHPartDataTypeException = Part.iHPartDataTypeExceptions(
                    priceCost,
                    inventoryLevel,
                    maxInvLevel,
                    minInvLevel,
                    machIDCompName,
                    iHPartDataTypeException);
        } else {
            partFieldException = Part.outsourcedPartFieldExceptions(
                    partName,
                    inventoryLevel,
                    priceCost,
                    minInvLevel,
                    maxInvLevel,
                    machIDCompName,
                    partFieldException);
            outsourcedPartDataTypeException = Part.outsourcedPartDataTypeExceptions(
                    priceCost,
                    inventoryLevel,
                    maxInvLevel,
                    minInvLevel,
                    outsourcedPartDataTypeException);
        }
        if (partFieldException.length() > 0) {
            System.err.println("Empty fields present in form.\nPart not added to inventory.");
            Alert emptyFields = new Alert(Alert.AlertType.WARNING);
            emptyFields.setTitle("ERROR: EMPTY FIELDS PRESENT");
            emptyFields.setHeaderText("This part has not been added to inventory");
            emptyFields.setContentText(partFieldException);
            emptyFields.showAndWait();
            partFieldException = "";
        } else if (iHPartDataTypeException.length() > 0) {
            System.err.println("Invalid data types present.\nPart not added to inventory.");
            Alert invalidIHDataTypes = new Alert(Alert.AlertType.WARNING);
            invalidIHDataTypes.setTitle("ERROR: INVALID DATA TYPES PRESENT");
            invalidIHDataTypes.setHeaderText("This part has not been added to inventory");
            invalidIHDataTypes.setContentText(iHPartDataTypeException);
            invalidIHDataTypes.showAndWait();
            iHPartDataTypeException = "";
        } else if (outsourcedPartDataTypeException.length() > 0) {
            System.err.println("Invalid data types present.\nPart not added to inventory.");
            Alert invalidOutDataTypes = new Alert(Alert.AlertType.WARNING);
            invalidOutDataTypes.setTitle("ERROR: INVALID DATA TYPES PRESENT");
            invalidOutDataTypes.setHeaderText("This part has not been added to inventory");
            invalidOutDataTypes.setContentText(outsourcedPartDataTypeException);
            invalidOutDataTypes.showAndWait();
            outsourcedPartDataTypeException = "";
        } else {
            try {
                partValueException = Part.partValueExceptions(
                        Double.parseDouble(priceCost),
                        Integer.parseInt(inventoryLevel),
                        Integer.parseInt(minInvLevel),
                        Integer.parseInt(maxInvLevel),
                        partValueException);
                if (partValueException.length() > 0) {
                    System.err.println("Invalid field values present.\nPart not added to inventory.");
                    Alert invalidValues = new Alert(Alert.AlertType.WARNING);
                    invalidValues.setTitle("ERROR: INVALID VALUES PRESENT");
                    invalidValues.setHeaderText("This part has not been added to inventory");
                    invalidValues.setContentText(partValueException);
                    invalidValues.showAndWait();
                    partValueException = "";
                } else {
                    if (inHousePart == true) {
                        InHouse inHouse = new InHouse();
                        inHouse.setId(partID);
                        inHouse.setName(partName);
                        inHouse.setStock(Integer.parseInt(inventoryLevel));
                        inHouse.setPrice(Double.parseDouble(priceCost));
                        inHouse.setMax(Integer.parseInt(maxInvLevel));
                        inHouse.setMin(Integer.parseInt(minInvLevel));
                        inHouse.setMachineID(Integer.parseInt(machIDCompName));
                        addPart(inHouse);
                        System.out.println("In-House part " + inHouse + " successfully added to inventory.");
                        Alert partAddSuccess = new Alert(Alert.AlertType.INFORMATION);
                        partAddSuccess.setTitle("SUCCESS: IN-HOUSE PART ADDED");
                        partAddSuccess.setHeaderText("In-House Part " + inHouse + " Successfully Added to Inventory");
                        partAddSuccess.setContentText("Click OK to return to the main screen.");
                        partAddSuccess.showAndWait();
                        if (partAddSuccess.getResult() == ButtonType.OK) {
                            System.out.println("Exiting to Main Screen.");
                            Parent root = FXMLLoader.load(getClass().getResource("/View/MainScreen.fxml"));
                            Scene mainScreen = new Scene(root);
                            Stage mainScreenWindow = (Stage) ((Node) event.getSource()).getScene().getWindow();
                            mainScreenWindow.setTitle("ABC Company: Inventory Management System");
                            mainScreenWindow.setScene(mainScreen);
                            mainScreenWindow.show();
                        } else {
                        }
                    } else {
                        Outsourced outsourced = new Outsourced();
                        outsourced.setId(partID);
                        outsourced.setName(partName);
                        outsourced.setStock(Integer.parseInt(inventoryLevel));
                        outsourced.setPrice(Double.parseDouble(priceCost));
                        outsourced.setMax(Integer.parseInt(maxInvLevel));
                        outsourced.setMin(Integer.parseInt(minInvLevel));
                        outsourced.setCompanyName(machIDCompName);
                        addPart(outsourced);
                        System.out.println("Outsourced part " + outsourced + " successfully added to inventory.");
                        Alert partAddSuccess = new Alert(Alert.AlertType.INFORMATION);
                        partAddSuccess.setTitle("SUCCESS: OUTSOURCED PART ADDED");
                        partAddSuccess.setHeaderText("Outsourced Part " + outsourced + " Successfully Added to Inventory");
                        partAddSuccess.setContentText("Click OK to return to the main screen.");
                        partAddSuccess.showAndWait();
                        if (partAddSuccess.getResult() == ButtonType.OK) {
                            System.out.println("Exiting to Main Screen.");
                            Parent root = FXMLLoader.load(getClass().getResource("/View/MainScreen.fxml"));
                            Scene mainScreen = new Scene(root);
                            Stage mainScreenWindow = (Stage) ((Node) event.getSource()).getScene().getWindow();
                            mainScreenWindow.setTitle("ABC Company: Inventory Management System");
                            mainScreenWindow.setScene(mainScreen);
                            mainScreenWindow.show();
                        } else {
                        }
                    }
                }
            } catch (IOException e) {
            }
        }
    }
@ FXML private void saveBtnHandler ( ActionEvent event ) throws IOException { String partName = partNameField . getText ( ) ; String inventoryLevel = invLevelField . getText ( ) ; String priceCost = priceCostField . getText ( ) ; String maxInvLevel = maxLevelField . getText ( ) ; String minInvLevel = minLevelField . getText ( ) ; String machIDCompName = dynamicField . getText ( ) ; if ( inHousePart == true ) { partFieldException = Part . inHousePartFieldExceptions ( partName , inventoryLevel , priceCost , minInvLevel , maxInvLevel , machIDCompName , partFieldException ) ; iHPartDataTypeException = Part . iHPartDataTypeExceptions ( priceCost , inventoryLevel , maxInvLevel , minInvLevel , machIDCompName , iHPartDataTypeException ) ; } else { partFieldException = Part . outsourcedPartFieldExceptions ( partName , inventoryLevel , priceCost , minInvLevel , maxInvLevel , machIDCompName , partFieldException ) ; outsourcedPartDataTypeException = Part . outsourcedPartDataTypeExceptions ( priceCost , inventoryLevel , maxInvLevel , minInvLevel , outsourcedPartDataTypeException ) ; } if ( partFieldException . length ( ) > 0 ) { System . err . println ( "Empty fields present in form.\nPart not added to inventory." ) ; Alert emptyFields = new Alert ( Alert . AlertType . WARNING ) ; emptyFields . setTitle ( "ERROR: EMPTY FIELDS PRESENT" ) ; emptyFields . setHeaderText ( "This part has not been added to inventory" ) ; emptyFields . setContentText ( partFieldException ) ; emptyFields . showAndWait ( ) ; partFieldException = "" ; } else if ( iHPartDataTypeException . length ( ) > 0 ) { System . err . println ( "Invalid data types present.\nPart not added to inventory." ) ; Alert invalidIHDataTypes = new Alert ( Alert . AlertType . WARNING ) ; invalidIHDataTypes . setTitle ( "ERROR: INVALID DATA TYPES PRESENT" ) ; invalidIHDataTypes . setHeaderText ( "This part has not been added to inventory" ) ; invalidIHDataTypes . setContentText ( iHPartDataTypeException ) ; invalidIHDataTypes . showAndWait ( ) ; iHPartDataTypeException = "" ; } else if ( outsourcedPartDataTypeException . length ( ) > 0 ) { System . err . println ( "Invalid data types present.\nPart not added to inventory." ) ; Alert invalidOutDataTypes = new Alert ( Alert . AlertType . WARNING ) ; invalidOutDataTypes . setTitle ( "ERROR: INVALID DATA TYPES PRESENT" ) ; invalidOutDataTypes . setHeaderText ( "This part has not been added to inventory" ) ; invalidOutDataTypes . setContentText ( outsourcedPartDataTypeException ) ; invalidOutDataTypes . showAndWait ( ) ; outsourcedPartDataTypeException = "" ; } else { try { partValueException = Part . partValueExceptions ( Double . parseDouble ( priceCost ) , Integer . parseInt ( inventoryLevel ) , Integer . parseInt ( minInvLevel ) , Integer . parseInt ( maxInvLevel ) , partValueException ) ; if ( partValueException . length ( ) > 0 ) { System . err . println ( "Invalid field values present.\nPart not added to inventory." ) ; Alert invalidValues = new Alert ( Alert . AlertType . WARNING ) ; invalidValues . setTitle ( "ERROR: INVALID VALUES PRESENT" ) ; invalidValues . setHeaderText ( "This part has not been added to inventory" ) ; invalidValues . setContentText ( partValueException ) ; invalidValues . showAndWait ( ) ; partValueException = "" ; } else { if ( inHousePart == true ) { InHouse inHouse = new InHouse ( ) ; inHouse . setId ( partID ) ; inHouse . setName ( partName ) ; inHouse . setStock ( Integer . parseInt ( inventoryLevel ) ) ; inHouse . setPrice ( Double . parseDouble ( priceCost ) ) ; inHouse . setMax ( Integer . parseInt ( maxInvLevel ) ) ; inHouse . setMin ( Integer . parseInt ( minInvLevel ) ) ; inHouse . setMachineID ( Integer . parseInt ( machIDCompName ) ) ; addPart ( inHouse ) ; System . out . println ( "In-House part " + inHouse + " successfully added to inventory." ) ; Alert partAddSuccess = new Alert ( Alert . AlertType . INFORMATION ) ; partAddSuccess . setTitle ( "SUCCESS: IN-HOUSE PART ADDED" ) ; partAddSuccess . setHeaderText ( "In-House Part " + inHouse + " Successfully Added to Inventory" ) ; partAddSuccess . setContentText ( "Click OK to return to the main screen." ) ; partAddSuccess . showAndWait ( ) ; if ( partAddSuccess . getResult ( ) == ButtonType . OK ) { System . out . println ( "Exiting to Main Screen." ) ; Parent root = FXMLLoader . load ( getClass ( ) . getResource ( "/View/MainScreen.fxml" ) ) ; Scene mainScreen = new Scene ( root ) ; Stage mainScreenWindow = ( Stage ) ( ( Node ) event . getSource ( ) ) . getScene ( ) . getWindow ( ) ; mainScreenWindow . setTitle ( "ABC Company: Inventory Management System" ) ; mainScreenWindow . setScene ( mainScreen ) ; mainScreenWindow . show ( ) ; } else { } } else { Outsourced outsourced = new Outsourced ( ) ; outsourced . setId ( partID ) ; outsourced . setName ( partName ) ; outsourced . setStock ( Integer . parseInt ( inventoryLevel ) ) ; outsourced . setPrice ( Double . parseDouble ( priceCost ) ) ; outsourced . setMax ( Integer . parseInt ( maxInvLevel ) ) ; outsourced . setMin ( Integer . parseInt ( minInvLevel ) ) ; outsourced . setCompanyName ( machIDCompName ) ; addPart ( outsourced ) ; System . out . println ( "Outsourced part " + outsourced + " successfully added to inventory." ) ; Alert partAddSuccess = new Alert ( Alert . AlertType . INFORMATION ) ; partAddSuccess . setTitle ( "SUCCESS: OUTSOURCED PART ADDED" ) ; partAddSuccess . setHeaderText ( "Outsourced Part " + outsourced + " Successfully Added to Inventory" ) ; partAddSuccess . setContentText ( "Click OK to return to the main screen." ) ; partAddSuccess . showAndWait ( ) ; if ( partAddSuccess . getResult ( ) == ButtonType . OK ) { System . out . println ( "Exiting to Main Screen." ) ; Parent root = FXMLLoader . load ( getClass ( ) . getResource ( "/View/MainScreen.fxml" ) ) ; Scene mainScreen = new Scene ( root ) ; Stage mainScreenWindow = ( Stage ) ( ( Node ) event . getSource ( ) ) . getScene ( ) . getWindow ( ) ; mainScreenWindow . setTitle ( "ABC Company: Inventory Management System" ) ; mainScreenWindow . setScene ( mainScreen ) ; mainScreenWindow . show ( ) ; } else { } } } } catch ( IOException e ) { } } }
Save Button tests for field/value/data type exceptions, creates
 in-house/outsourced parts, displays alerts, navigates user back to main
 screen upon successful part addition.
Save Button tests for field / value / data type exceptions creates in - house / outsourced parts displays alerts navigates user back to main screen upon successful part addition .