In: Computer Science
For a supermarket, define a Inventory class. All the Inventory
objects will contain
S,No, name of clerk preparing the inventory, each item with id,
quantity available
, minimum order quantity ,price and date of expiry. There is an
array to describe
the above details. Your program generate the stock based on the
items quantity is
equal to minimum order quantity or less than minimum order quantity
and also
display items to check date of expiry with current date.
file-name: Inventory.java -------------------------------- import java.time.LocalDate; /** * Inventory class * All the Inventory objects will contain * S.No, name of clerk preparing the inventory, each item with id, quantity available * , minimum order quantity ,price and date of expiry. */ public class Inventory { int serialNo; String clerkName; String itemId; double quantityAvailable; double minOrderQuantity; double price; LocalDate expiryDate; Inventory(int serialNo, String clerkName, String itemId, double quantityAvailable, double minOrderQuantity, double price,LocalDate expiryDate) { this.serialNo = serialNo; this.clerkName = clerkName; this.itemId = itemId; this.quantityAvailable = quantityAvailable; this.minOrderQuantity = minOrderQuantity; this.price = price; this.expiryDate = expiryDate; } // END of constructor public String getItemId() { return itemId; } public LocalDate getExpiryDate() { return expiryDate; } public double getQuantityAvailable() { return quantityAvailable; } public double getMinOrderQuantity() { return minOrderQuantity; } public void setQuantityAvailable(double quantityAvailable) { this.quantityAvailable = quantityAvailable; } // to display item id , date of expiry and current date. public String toString() { String str = "Item ID: "+getItemId() + "\nExpiry Date: "+getExpiryDate() + "\nCurrent Date: "+ LocalDate.now() +"\n--------------"; return str; } } // END of class
=====================================
file-name: TestMain.java ------------------------- import java.time.LocalDate; // This class is to show the working of inventory class and create the objects of Inventory class. public class TestMain { public static void main(String[] args) { // creating an example Inventory array of size 6,( if you want to add more and more then better user ArrayList ) Inventory[] inventoryItems = new Inventory[6]; // If you want to add the items to inventory by taking user input. // Then use Scanner class and read user input, and then create a Inventory object using those values. inventoryItems[0] = new Inventory(1,"John", "PEN1", 50 , 10, 10,LocalDate.of(2025,2,14)); inventoryItems[1] = new Inventory(2,"Iqbal", "PEN2", 70 , 10,7, LocalDate.of(2023,8,12)); inventoryItems[2] = new Inventory(3,"John", "SHIRT", 15 , 2, 100 ,LocalDate.of(2022,1,12)); inventoryItems[3] = new Inventory(4,"Iqbal", "TROU", 25 , 1,120, LocalDate.of(2022,7,1)); inventoryItems[4] = new Inventory(5,"Parvinder", "DAL", 500 , 15,50, LocalDate.of(2020,12,31)); inventoryItems[5] = new Inventory(6,"John", "BAT", 50 , 1, 175, LocalDate.of(2025,2,14)); System.out.println("The initial quantity is: "+inventoryItems[0].getQuantityAvailable()); // I am setting the quantity available for item at index 0,to minimum order quantity // Just to show how it works. inventoryItems[0].setQuantityAvailable(10); System.out.println("The quantity available now is: "+inventoryItems[0].getQuantityAvailable()); // now calling a method adjustQuantity( ) to generate stock. adjustQuantity(inventoryItems[0]); System.out.println("The quantity available after adjusting stock: "+inventoryItems[0].getQuantityAvailable()); System.out.println("The initial quantity is: "+inventoryItems[2].getQuantityAvailable()); // making quantity available to less than minimum order quantity inventoryItems[2].setQuantityAvailable(1); System.out.println("The quantity available now is: "+inventoryItems[2].getQuantityAvailable()); adjustQuantity(inventoryItems[2]); System.out.println("The quantity available after adjusting stock: "+inventoryItems[2].getQuantityAvailable());
System.out.println(inventoryItems[0]); System.out.println(inventoryItems[5]); System.out.println(inventoryItems[3]);
} // END of main( ) method /** * Takes inventory object as a parameter. * Triples the quantity available only , if the available quantity is less than or equal to minimum order quantity. * @param item */ public static void adjustQuantity(Inventory item) { if(item.getQuantityAvailable() <= item.getMinOrderQuantity()) { item.setQuantityAvailable(3*item.getQuantityAvailable()); System.out.println("This item soon will be out of stock, so Tripled the quantity available"); } else { System.out.println("Sufficient quantity of item is there in inventory, no need to increase the quantity as of now!"); } } // END of adjustQuantity( ) method } // END of TestMain class
=====================================================================================
OUTPUT:
Hey, Thank you!! If you need anything more or any doubts ask in comment section I will modify answer as per requirement. Please UPVOTE if you like my effort.