forked from pranjay-poddar/Dev-Geeks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Inventory management System using Java Swing (pranjay-poddar#…
…1901) * created inventory mangement * create inventory management * create inventory manage ment * ``` added readme ``` * Update README.md
- Loading branch information
1 parent
ff57407
commit 770b74f
Showing
5 changed files
with
280 additions
and
6 deletions.
There are no files selected for viewing
178 changes: 178 additions & 0 deletions
178
Java Projects/Inventory Management System/InventoryManagementSystemGUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters