Question

I need code for this in Java We need a command line app that will be...

I need code for this in Java

We need a command line app that will be able to illustrate collecting data for inventory and showing purchases of that inventory. Start with a menu system that will allow the user to choose between functionality.

  • Show a list of products (inventory)
  • Add inventory (price, description, who is selling)
  • Delete inventory
  • Purchase a product for a user (removing it from inventory)
  • Show a list of products sold including their purchaser
  • Make sure to have dates on all activity

Type the UML diagram for the classes in the design portion. Feel free to add any other fields that you would like to share.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I don't understand the requirements u want the working app or the source code?

JAVA SOURCE CODE:

import com.jfoenix.controls.JFXRadioButton;
import com.jfoenix.controls.JFXTextField;
import java.io.IOException;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;

/**
* FXML Controller class
*
* @author NixonOK
*/

// It's the Add Products/ Modify Products window controller class
// It impliments initializables as default, it is kind of a start() method to initialize things at startup
public class AddProductInterfaceController implements Initializable {

/**
* Initializes the controller class.
*/
  
/*----------------------------------------All FXML Button, Field, RadioButton,Label Declaration-----------------------*/
@FXML private JFXRadioButton inHouseButton, outsourcedButton;
@FXML private JFXTextField companyNameField, productPriceField, productMaxField, productMinField, productNameTextField, productLnvField, productIDTextField;
@FXML private Label companyNameLabel;

@FXML
TableView<Part> partsTable, partsTable1;

@FXML
private TableColumn<Part, Integer> partsID, partsLevel, partsID1, partsLevel1;

@FXML
private TableColumn<Part, Double> partsCost, partsCost1;
  
@FXML
private TableColumn<Part, String> partsName, partsName1;
  
private IMSFXMLDocumentController documentController;

Product productSelected;
Part partSelected;
Boolean editData = false;
ObservableList<Part> productParts = FXCollections.observableArrayList();
ObservableList<Part> existingProductParts = FXCollections.observableArrayList();
  
// Method is called when a product associated part is selected and modify button is pressed
@FXML
void productPartEditAction(ActionEvent event) {
// when a part is selected
if (partSelected != null) {
try {
// Loading the add product interface
FXMLLoader loader = new FXMLLoader(getClass().getResource("AddProductPartInterface.fxml"));
Parent root;
root = (Parent) loader.load();
Stage stage = new Stage();
stage.setTitle("Modify Product Part Window");
stage.setScene(new Scene(root));
// setting this window as parent   
loader.<AddProductPartInterfaceController>getController()
.setParentController(this);

AddProductPartInterfaceController api = loader.getController();
// sending selected part as parameter for field auto fill
api.setPart(partSelected);
stage.show();

} catch (IOException ex) {
Logger.getLogger(IMSFXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
// when no part is selected
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Error!");
alert.setHeaderText("Please, Select at-least one part to perform modify operation!");
alert.setContentText(null);

alert.showAndWait();
}

}

// Method is called when a product associated part is selected and delete button is pressed
@FXML
void productPartDeleteAction(ActionEvent event) {
//when a part is selected
if (partSelected != null) {
// Showing alert to confirm deletion
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Causion!");
alert.setHeaderText("Are you sure you want to delete Part with ID : " + partSelected.getPartsID() + "?");
alert.setContentText(null);
  
Optional<ButtonType> result = alert.showAndWait();
  
// if the user confirms delete the part
if (result.get() == ButtonType.OK) {
partsTable.getItems().remove(partSelected);
productParts.remove(partSelected);
  
documentController.parts.remove(partSelected);
documentController.partsTable.getItems().remove(partSelected);
}
}else {
// when no part is selected
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Error!");
alert.setHeaderText("Please, Select at-least one part to perform delete operation!");
alert.setContentText(null);

alert.showAndWait();
}

}

// Method is called when a product associated part is selected and De-Associate button is pressed
@FXML
void productPartDeAssociateAction(ActionEvent event) {
//when a part is selected
if (partSelected != null) {
// showing the causing message and confirm dialog
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Causion!");
alert.setHeaderText("Are you sure you want to De-Associate Part with ID : " + partSelected.getPartsID() + " From this Product?");
alert.setContentText(null);
  
Optional<ButtonType> result = alert.showAndWait();
// when confirmed
if (result.get() == ButtonType.OK) {
// delete parts from products table and deassociate them
partsTable.getItems().remove(partSelected);
productParts.remove(partSelected);
partSelected.setAssociatedPartID(-1);
}
}else {
// when no part is selected
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Error!");
alert.setHeaderText("Please, Select at-least one part to perform delete operation!");
alert.setContentText(null);

alert.showAndWait();
}

}

// when close button on product window is clicked
@FXML
void closeButtonAction(ActionEvent event){
// Close current window
final Node source = (Node) event.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();

}
  
// This method is called when new products associated new part add button is clicked
@FXML
private void addProductAssociatedPart(ActionEvent event) {
  
try {
// Load the addproductpart window
FXMLLoader loader = new FXMLLoader(getClass().getResource("AddProductPartInterface.fxml"));
Parent root;
root = (Parent) loader.load();
Stage stage = new Stage();
stage.setTitle("Add Product Part Window");
stage.setScene(new Scene(root));
  
loader.<AddProductPartInterfaceController>getController()
.setParentController(this);
  
AddProductPartInterfaceController api = loader.getController();
// sending information about the product id the part is going to be associated with
api.setID(documentController.generatePartsID());
api.setAssociatedPart(Integer.parseInt(productIDTextField.getText()));
stage.show();
  
  
} catch (IOException ex) {
Logger.getLogger(IMSFXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
}

}
  
// This method is called when in products window save button is pressed
@FXML
void productSaveButtonAction(ActionEvent event){
// if product has at-least one parts
if(productParts.isEmpty() == false || existingProductParts.isEmpty() == false){
// If the inventory level is lower then max
if (Integer.parseInt(productMaxField.getText()) > Integer.parseInt(productMinField.getText())) {
// If max is lower then min
if (Integer.parseInt(productLnvField.getText()) < Integer.parseInt(productMaxField.getText())) {
// If the modify button was clicked
if (editData == true) {
// update the product information
documentController.updateProduct(
Integer.parseInt(productIDTextField.getText()),
productNameTextField.getText(),
Integer.parseInt(productLnvField.getText()),
Double.parseDouble(productPriceField.getText()),
productSelected,
Integer.parseInt(productMaxField.getText()),
Integer.parseInt(productMinField.getText())
);

// Show succefully new part addition dialog
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Success!");
alert.setHeaderText("Successfully Updated Product Information!");
alert.setContentText(null);
alert.showAndWait();
} else {
// if add new product button was pressed
// add the new part to the main arraylist
documentController.addNewProduct(
Integer.parseInt(productIDTextField.getText()),
productNameTextField.getText(),
Integer.parseInt(productLnvField.getText()),
Double.parseDouble(productPriceField.getText()),
Integer.parseInt(productMaxField.getText()),
Integer.parseInt(productMinField.getText())
);

// Show succefully new part addition dialog
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Success!");
alert.setHeaderText("Successfully Added new Product!");
alert.setContentText(null);
alert.showAndWait();
}

// Closing the window after the save/update has been successfully finished
final Node source = (Node) event.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
} else {
// Show succefully new part addition dialog
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error!");
alert.setHeaderText("Max value can not be lower then inventory level value!");
alert.setContentText(null);
alert.showAndWait();
}

} else {
// Show succefully new part addition dialog
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error!");
alert.setHeaderText("Max value can not be lower then min value!");
alert.setContentText(null);
alert.showAndWait();
}
} else {
// Show succefully new part addition dialog
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error!");
alert.setHeaderText("Products must have atleast one part!");
alert.setContentText(null);
alert.showAndWait();
}
}

@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO

// setting add new parts table collumns cell value factory
partsID.setCellValueFactory(new PropertyValueFactory<>("partsID"));
partsLevel.setCellValueFactory(new PropertyValueFactory<>("partsLevel"));
partsCost.setCellValueFactory(new PropertyValueFactory<>("partsCost"));
partsName.setCellValueFactory(new PropertyValueFactory<>("partsName"));
// setting add product associated parts table collumns cell value factory
partsID1.setCellValueFactory(new PropertyValueFactory<>("partsID"));
partsLevel1.setCellValueFactory(new PropertyValueFactory<>("partsLevel"));
partsCost1.setCellValueFactory(new PropertyValueFactory<>("partsCost"));
partsName1.setCellValueFactory(new PropertyValueFactory<>("partsName"));
// setting add click event for parts selection for future delete or modify action
partsTable.setOnMousePressed(new EventHandler<MouseEvent>() {

@Override
public void handle(MouseEvent event) {
// Getting the selected object and saving for use
partSelected = partsTable.getSelectionModel().getSelectedItem();

}
});
}
  
// default parent controller setter method
void setParentController(IMSFXMLDocumentController documentController) {
this.documentController = documentController;
}

// this method receives product data from main window when a product is selected and modify button is pressed
void setData(Product productSelected) {
  
productIDTextField.setText(""+productSelected.getProductID());
productNameTextField.setText(productSelected.getProductName());
productLnvField.setText("" + productSelected.getProductLevel());
productPriceField.setText("" + productSelected.getProductCost());
productMaxField.setText("" + productSelected.getProductMax());
productMinField.setText("" + productSelected.getProductMin());
this.productSelected = productSelected;
editData = true;
}

// Product id auto generation for new product
void setData(int generateProductsID) {
productIDTextField.setText(""+generateProductsID);
}
  
// Add associated parts for modify products window
void addToTempProductTableView(int pID, String pName, int pLevel, double pCost, int pMax, int pMin, String pCompMac, Boolean inHouse, int asID){
  
productParts.add(new Part( pID, pName, pLevel, pCost, pMax, pMin, pCompMac, inHouse, asID));
  
partsTable1.getItems().clear();
partsTable1.getItems().setAll(productParts);

documentController.addNewPart(pID, pName, pLevel, pCost, pMax, pMin, pCompMac, inHouse, asID);

}
  
// update part info for modify part button click event
void updatePart(int pID, String pName, int pLevel, double pCost, Part selectedPart, int pMax, int pMin, String pCompMach, Boolean inHouse, int asID) {
  
partSelected.setPartsCost(pID);
partSelected.setPartsName(pName);
partSelected.setPartsLevel(pLevel);
partSelected.setPartsCost(pCost);
partSelected.setPartMax(pMax);
partSelected.setPartMin(pMin);
partSelected.setCompanyNameOrMachineID(pCompMach);
partSelected.setInHouse(inHouse);
partSelected.setAssociatedPartID(asID);
partsTable.getItems().clear();
partsTable.getItems().setAll(existingProductParts);
  
documentController.updatePart(pID, pName, pLevel, pCost, selectedPart, pMax, pMin, pCompMach, inHouse, asID);
  
}
  


}

Add a comment
Know the answer?
Add Answer to:
I need code for this in Java We need a command line app that will be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Inventory Management Code Question

    Inventory ManagementObjectives:Use inheritance to create base and child classesUtilize multiple classes in the same programPerform standard input validationImplement a solution that uses polymorphismProblem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes...

  • I tried to complete a Java application that must include at a minimum: Three classes minimum...

    I tried to complete a Java application that must include at a minimum: Three classes minimum At least one class must use inheritance At least one class must be abstract JavaFX front end – as you will see, JavaFX will allow you to create a GUI user interface. The User Interface must respond to events. If your application requires a data backend, you can choose to use a database or to use text files. Error handling - The application should...

  • Need help working through CLion: Description: For this assignment you will create a program to manage...

    Need help working through CLion: Description: For this assignment you will create a program to manage phone contacts. Your program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. Your program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2....

  • JAVA We are learning about java databases in my highschool java class. I Need some help...

    JAVA We are learning about java databases in my highschool java class. I Need some help with it. Create a Java program (feel free to do it all in a main method) that works with a database that contains your 'Contractors' table (see the last exercise). Id (integer, primary key) CompanyName (varchar, 30 characters) Phone(varchar, 12 characters) ContactName(varchar, 30 characters) Rating (integer) OutOfStateService (boolean) # company name phone # Name rating Out of state service 1 Joe's Brewery 1111111111 Joe...

  • Problem: Contact Information Sometimes we need a program that have all the contact information like name,...

    Problem: Contact Information Sometimes we need a program that have all the contact information like name, last name, telephone, direction and something we need to know about that person (notes). Write a program in java language with GUI, classes, arrays, files and inheritance that make this possible. In the first layer, the user should see all the contacts and three buttons (add, delete, edit). *Add button: If the user click the button add, a new layer should appear and should...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Android Problem Using JAVA Problem: You need to create an app on Android Studios that allows...

    Android Problem Using JAVA Problem: You need to create an app on Android Studios that allows users to register and login into the system. The focus of this project is for you to create an app with several activities and has data validation. You should have for your app: A welcome screen (splash screen) with your app name and a picture. You should then move to a screen that asks the user for either to log in or to register....

  • is due in 2 hours so i had to repost, sorry. Create an application that allows...

    is due in 2 hours so i had to repost, sorry. Create an application that allows you to manage a task list that’s stored in a database. using java and netbeans Console: Task List COMMAND MENU view - View pending tasks history -View completed tasks add -Add a task complete -Complete a task delete -Delete a task exit -Exit program Command: view 1. Buy toothbrush 2. Do homework Command: complete Number: 2 Command: add Description: Pay bills Command: view 1....

  • language:python VELYIEW Design a program that you can use to keep information on your family or...

    language:python VELYIEW Design a program that you can use to keep information on your family or friends. You may view the video demonstration of the program located in this module to see how the program should function. Instructions Your program should have the following classes: Base Class - Contact (First Name, Last Name, and Phone Number) Sub Class - Family (First Name, Last Name, Phone Number, and Relationship le. cousin, uncle, aunt, etc.) Sub Class - Friends (First Name, Last...

  • THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU....

    THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU. Program 1 Write an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for getting information such as the volume and the surface area of a three-dimensional shape. Then make classes and subclasses that implement various shapes such as cube, cylinders and spheres. Place common behavior in superclasses whenever possible, and use abstract classes as appropriate. Add methods to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT