Experiment 4a
Experiment 4a
UID: 2024800052
Experiment No. 4A
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:
class Product {
int stockQuantity;
}
class Warehouse {
String[] productNames;
int[] stockQuantities;
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);