Skip to content

Commit

Permalink
Created Inventory management System using Java Swing (pranjay-poddar#…
Browse files Browse the repository at this point in the history
…1901)

* created inventory mangement

* create inventory management

* create inventory manage ment

* ```
added readme
```

* Update README.md
  • Loading branch information
amelia2802 authored Jun 9, 2023
1 parent ff57407 commit 770b74f
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class InventoryManagementSystemGUI extends JFrame {

private JLabel nameLabel;
private JTextField nameTextField;
private JLabel priceLabel;
private JTextField priceTextField;
private JLabel quantityLabel;
private JTextField quantityTextField;
private JButton addButton;
private JButton updateButton;
private JButton removeButton;
private JButton checkButton;

private JTextArea outputTextArea;

private Product[] products;

public InventoryManagementSystemGUI() {
super("Inventory Management System");
initializeComponents();
createLayout();
createListeners();
initializeProducts();
}

private void initializeComponents() {
nameLabel = new JLabel("Product Name:");
nameTextField = new JTextField(20);
priceLabel = new JLabel("Price:");
priceTextField = new JTextField(10);
quantityLabel = new JLabel("Quantity:");
quantityTextField = new JTextField(10);
addButton = new JButton("Add");
updateButton = new JButton("Update");
removeButton = new JButton("Remove");
checkButton = new JButton("Check");
outputTextArea = new JTextArea(10, 40);
outputTextArea.setEditable(false);
}

private void createLayout() {
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(6, 2));
panel.add(nameLabel);
panel.add(nameTextField);
panel.add(priceLabel);
panel.add(priceTextField);
panel.add(quantityLabel);
panel.add(quantityTextField);
panel.add(addButton);
panel.add(updateButton);
panel.add(removeButton);
panel.add(checkButton);

JScrollPane scrollPane = new JScrollPane(outputTextArea);

Container container = getContentPane();
container.setLayout(new BorderLayout());
container.add(panel, BorderLayout.NORTH);
container.add(scrollPane, BorderLayout.CENTER);
}

private void createListeners() {
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameTextField.getText();
double price = Double.parseDouble(priceTextField.getText());
int quantity = Integer.parseInt(quantityTextField.getText());
Product product = new Product(name, price, quantity);
products = addProduct(products, product);
outputTextArea.append("Product added: " + product.getName() + "\n");
clearInputFields();
}
});

updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameTextField.getText();
double price = Double.parseDouble(priceTextField.getText());
int quantity = Integer.parseInt(quantityTextField.getText());
Product product = new Product(name, price, quantity);
products = updateProduct(products, product);
outputTextArea.append("Product updated: " + product.getName() + "\n");
clearInputFields();
}
});

removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameTextField.getText();
products = removeProduct(products, name);
outputTextArea.append("Product removed: " + name + "\n");
clearInputFields();
}
});

checkButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameTextField.getText();
checkProduct(products, name);
clearInputFields();
}
});
}

private void initializeProducts() {
int n = Integer.parseInt(JOptionPane.showInputDialog("Please enter the number of products you want to add: "));
products = new Product[n];
for (int i = 0; i < n; i++) {
String name = JOptionPane.showInputDialog("Please enter the name of the product: ");
double price = Double.parseDouble(JOptionPane.showInputDialog("Please enter the price of the product: "));
int quantity = Integer.parseInt(JOptionPane.showInputDialog("Please enter the quantity of the product: "));
products[i] = new Product(name, price, quantity);
}
}

private void clearInputFields() {
nameTextField.setText("");
priceTextField.setText("");
quantityTextField.setText("");
}

public static Product[] addProduct(Product[] products, Product product) {
Product[] newProducts = new Product[products.length + 1];
System.arraycopy(products, 0, newProducts, 0, products.length);
newProducts[products.length] = product;
return newProducts;
}

public static Product[] updateProduct(Product[] products, Product product) {
Product[] newProducts = new Product[products.length];
for (int i = 0; i < products.length; i++) {
if (products[i].getName().equals(product.getName())) {
newProducts[i] = product;
} else {
newProducts[i] = products[i];
}
}
return newProducts;
}

public static Product[] removeProduct(Product[] products, String name) {
Product[] newProducts = new Product[products.length - 1];
int j = 0;
for (int i = 0; i < products.length; i++) {
if (!products[i].getName().equals(name)) {
newProducts[j] = products[i];
j++;
}
}
return newProducts;
}

public static void checkProduct(Product[] products, String name) {
for (Product product : products) {
if (product.getName().equals(name)) {
JOptionPane.showMessageDialog(null, "Product found!\n" +
"Name: " + product.getName() + "\n" +
"Price: " + product.getPrice() + "\n" +
"Quantity: " + product.getQuantity());
return;
}
}
JOptionPane.showMessageDialog(null, "Product not found!");
}

public static void main(String[] args) {
InventoryManagementSystemGUI frame = new InventoryManagementSystemGUI();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
35 changes: 35 additions & 0 deletions Java Projects/Inventory Management System/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class Product {
private String name;
private double price;
private int quantity;

public Product(String name, double price, int quantity) {
this.name = name;
this.price = price;
this.quantity = quantity;
}

public String getName() {
return name;
}

public double getPrice() {
return price;
}

public int getQuantity() {
return quantity;
}

public void setName(String name) {
this.name = name;
}

public void setPrice(double price) {
this.price = price;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
51 changes: 51 additions & 0 deletions Java Projects/Inventory Management System/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Inventory Management System

The Inventory Management System is a simple **Java-based** application that allows users to manage an inventory of products.It makes use of the **Swing framework** for creating the **graphical user interface (GUI)**. It provides functionalities such as adding new products, updating existing products, removing products, and checking the availability of products.

## Features

- Add new products: Users can enter the details of a product, including its name, price, and quantity, and add it to the inventory.
- Update existing products: Users can update the price and quantity of an existing product in the inventory.
- Remove products: Users can remove a product from the inventory based on its name.
- Check product availability: Users can search for a product by its name and view its details, including price and quantity.

## Demo


https://github.com/amelia2802/inventory-management/assets/49182604/35eecb97-958c-4bed-bdff-6c9e97a0d279


### Running the Program

1. Compile the Java files by executing the following command:
```
javac Product.java InventoryManagementSystemGUI.java
```

2. Run the program using the following command:
```
java InventoryManagementSystemGUI
```

3. The Inventory Management System GUI will open, allowing you to interact with the application.

## Usage

1. Upon launching the application, you will be prompted to enter the number of products you want to add to the inventory.

2. Enter the details of each product, including its name, price, and quantity.

3. After adding the initial products, you will be asked to enter the number of operations you want to perform.

4. Choose an operation from the available options:
- Add: Add a new product to the inventory by providing its details.
- Update: Update the price and quantity of an existing product by providing its name and new details.
- Remove: Remove a product from the inventory by entering its name.
- Check: Check the availability of a product by entering its name.

5. Follow the on-screen instructions and provide the necessary information to perform the chosen operation.

6. Repeat steps 4 and 5 for additional operations if desired.

### Resources:
- Programming with Java - E Balagurusamy
11 changes: 11 additions & 0 deletions Java Projects/Shop/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1686121992241</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,10 @@ Happy Coding! -->
<tr align="center">
<td align="center"> 229.</td>
<td align="center"> <a href="https://github.com/pranjay-poddar/Dev-Geeks/tree/main/Python%20Projects/Hangman-advanced"> Hangman-Advanced </a></td>
<td align="center"> 228.</td>
<td align="center"> <a href="https://github.com/pranjay-poddar/Dev-Geeks/tree/main/Frontend-Projects/FIght%20Game"> Fight Game </a></td>


</tr>


</table>

<td align="center"> 229.</td>
<td align="center"> <a href="https://github.com/pranjay-poddar/Dev-Geeks/tree/main/Node-JS%20Projects/Secrets"> Secrets </a></td>
<td align="center"> 230.</td>
Expand All @@ -729,10 +725,13 @@ Happy Coding! -->
<td align="center"> <a href="https://github.com/pranjay-poddar/Dev-Geeks/tree/main/ML%20Projects/Analysis%20of%20Fashion_dataset"> Amazing Snake Game </a></td>
<td align="center"> 232</td>
<td align="center"> <a href="https://github.com/pranjay-poddar/Dev-Geeks/tree/main/Js-Projects/Colovaria"> Colovaria </a></td>
<td align="center"> *</td>
<td align="center"> <a href="https://github.com/pranjay-poddar/Dev-Geeks/tree/main/Java%20Projects/Inventory%20Management%20System"> Inventory Management System </a></td>
</tr>
</table>



</table>
Node-JS Projects\Secrets
## How to contribute:

Expand Down

0 comments on commit 770b74f

Please sign in to comment.