0% found this document useful (0 votes)
9 views7 pages

Experiment 4a

The document outlines a Java program for a warehouse stock management system that tracks product stock levels. It includes functionalities such as displaying stock details, identifying products with the highest and lowest stock, updating stock levels, and checking for out-of-stock products. The experiment demonstrates effective inventory management through the use of arrays.

Uploaded by

nachiket.kale24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Experiment 4a

The document outlines a Java program for a warehouse stock management system that tracks product stock levels. It includes functionalities such as displaying stock details, identifying products with the highest and lowest stock, updating stock levels, and checking for out-of-stock products. The experiment demonstrates effective inventory management through the use of arrays.

Uploaded by

nachiket.kale24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Nachiket Kale

UID: 2024800052

Experiment No. 4A

AIM: ARRAYS / STRING ARRAYS

Program 1

PROBLEM Imagine you are working for a company that manages a warehouse.
STATEMENT : The warehouse stores different types of products, and you are tasked
with implementing a system to track the stock levels of these
products. Each product has a specific identifier, and you need to
monitor how much stock of each product is currently available. You
need to take input from users (keyboard input) where each element
represents the current stock of a particular product in the warehouse.
You need to implement the following functionalities:

1.​ Print details of available stock.


2.​ Find the product with the highest stock.
3.​ Find the product with the lowest stock.
4.​ Update the stock level and print an updated stock. (add or
subtract quantity of stock)
5.​ Check if any product is out of stock: Determine if there is any
product in the warehouse that has zero stock left

PROGRAM: import java.util.Scanner;

class Product {
​ int stockQuantity;
}

class Warehouse {
​ String[] productNames;
​ int[] stockQuantities;

​ public Warehouse(int numProducts) {


​ productNames = new String[numProducts];
​ stockQuantities = new int[numProducts];
​ }

​ public void addProduct(int index, String name, int quantity) {


​ productNames[index] = name;
​ stockQuantities[index] = quantity;
​ }

​ public void displayStock() {


​ for (int i = 0; i < productNames.length; i++) {
​ System.out.println("Product: " + productNames[i] + ", Stock: " +
stockQuantities[i]);
​ }
​ }

​ public void displayHighestStock() {


​ int maxStockIndex = 0;
​ for (int i = 1; i < stockQuantities.length; i++) {
​ if (stockQuantities[i] > stockQuantities[maxStockIndex]) {
​ maxStockIndex = i;
​ }
​ }
​ System.out.println("Product with highest stock: " +
productNames[maxStockIndex] + ", Stock: " +
stockQuantities[maxStockIndex]);
​ }

​ public void displayLowestStock() {


​ int minStockIndex = 0;
​ for (int i = 1; i < stockQuantities.length; i++) {
​ if (stockQuantities[i] < stockQuantities[minStockIndex]) {
​ minStockIndex = i;
​ }
​ }
​ System.out.println("Product with lowest stock: " +
productNames[minStockIndex] + ", Stock: " +
stockQuantities[minStockIndex]);
​ }

​ public void updateStock(String productName, int quantityChange) {


​ for (int i = 0; i < productNames.length; i++) {
​ if (productNames[i].equals(productName)) {
​ stockQuantities[i] += quantityChange;
​ System.out.println("Updated stock for " + productNames[i]
+ ": " + stockQuantities[i]);
​ return;
​ }
​ }
​ System.out.println("Product not found.");
​ }

​ public void checkOutOfStock() {


​ boolean foundOutOfStock = false;
​ for (int i = 0; i < stockQuantities.length; i++) {
​ if (stockQuantities[i] == 0) {
​ System.out.println("Product " + productNames[i] + " is out
of stock!");
​ foundOutOfStock = true;
​ }
​ }
​ if (!foundOutOfStock) {
​ System.out.println("No products are out of stock.");
​ }
​ }
}

class Options {
​ public void showOptions(Warehouse warehouse, Scanner sc) {
​ int choice;
​ do {
​ System.out.println("\n1. Displaying Stock details");
​ System.out.println("2. Displaying Product with highest stock");
​ System.out.println("3. Displaying Product with lowest stock");
​ System.out.println("4. Select a product to update stock level");
​ System.out.println("5. Displaying products which are out of stock");
​ System.out.println("0. Exit");

​ choice = sc.nextInt();
​ sc.nextLine();

​ switch (choice) {
​ case 1:
​ warehouse.displayStock();
​ break;

​ case 2:
​ warehouse.displayHighestStock();
​ break;

​ case 3:
​ warehouse.displayLowestStock();
​ break;

​ case 4:
​ System.out.print("Enter product name to update stock: ");
​ String productName = sc.nextLine();
​ System.out.print("Enter the quantity to add/subtract: ");
​ int quantityChange = sc.nextInt();
​ warehouse.updateStock(productName, quantityChange);
​ break;

​ case 5:
​ warehouse.checkOutOfStock();
​ break;

​ case 0:
​ System.out.println("Exiting the system.");
​ break;

​ default:
​ System.out.println("Invalid option. Please try again.");
​ }
​ } while (choice != 0);
​ }
}
public class WarehouseSystem {
​ public static void main(String[] args) {
​ Scanner sc = new Scanner(System.in);

​ System.out.print("Enter the number of products: ");


​ int numProducts = sc.nextInt();
​ sc.nextLine();

​ Warehouse warehouse = new Warehouse(numProducts);

​ for (int i = 0; i < numProducts; i++) {


​ System.out.print("Enter product name for product " + (i + 1) + ": ");
​ String productName = sc.nextLine();
​ System.out.print("Enter stock quantity for " + productName + ": ");
​ int stockQuantity = sc.nextInt();
​ sc.nextLine();
​ warehouse.addProduct(i, productName, stockQuantity);
​ }

​ Options options = new Options();


​ options.showOptions(warehouse, sc);
​ }
}
RESULT:
CONCLUSION: This experiment successfully implements a warehouse stock management
system using arrays. It tracks stock levels, identifies products with the
highest and lowest stock, and allows stock updates. The system also detects
out-of-stock products, ensuring efficient inventory management. This
approach helps streamline warehouse operations effectively.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy