Question

In: Computer Science

For a supermarket, define a Inventory class. All the Inventory objects will contain S,No, name of...

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.

Solutions

Expert Solution

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.


Related Solutions

Create a class named GameCharacter to define an object as follows: The class should contain class...
Create a class named GameCharacter to define an object as follows: The class should contain class variables for charName (a string to store the character's name), charType (a string to store the character's type), charHealth (an int to store the character's health rating), and charScore (an int to store the character's current score). Provide a constructor with parameters for the name, type, health and score and include code to assign the received values to the four class variables. Provide a...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods designed to perform simple conversions. Specifically, you will be writing methods to convert temperature between Fahrenheit and Celsius and length between meters and inches and practicing overloading methods. See the API document for the Conversion class for a list of the methods you will write. Also, because all of the methods of the Conversion class will be static, you should ensure that it is...
a. What is/are the name(s) of the functional group(s) that contain oxygen in the two molecules...
a. What is/are the name(s) of the functional group(s) that contain oxygen in the two molecules we are using in this lab (ethyl acetate and butyl acetate)? b. Define “boiling point”. c. If Compound A has a higher boiling point than Compound B, how do their vapor pressures compare? Choose all of the correct answers among: “A is higher than B”, “B is higher than A”, “A and B are about the same”, “depends on the atmospheric pressure”, or “depends...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
Define a JAVA class ISP. The class consists of the name of the subscription plan and...
Define a JAVA class ISP. The class consists of the name of the subscription plan and a method that display the plan. Derive a class DPlan from ISP. The DPlan will charge RM10 per Mbps subscribe and RM0.20 per GB used. Derive a class MPlan from ISP. The MPlan will charge RM5 per Mbps subscribe and RM0.80 per GB used. Display the plan and select the best plan.
Python Please Define a class that will represent soccer players as objects. A soccer player will...
Python Please Define a class that will represent soccer players as objects. A soccer player will have as attributes, name, age, gender, team name, play position on the field, total career goals scored. The class should have the following methods: 1. initializer method that will values of data attributes arguments. Use 0 as default for career goals scored. 2. str method to return all data attributes as combined string object. 3. addToGoals that will accept an argument of int and...
Define a class Fraction3YourName as follows, /** * Program Name: Fraction3YourName.java * Discussion: Fraction3Yourname class *...
Define a class Fraction3YourName as follows, /** * Program Name: Fraction3YourName.java * Discussion: Fraction3Yourname class * written By: * Date: 2019/09/19 */ public class Fraction3YourName { private int sign; private int num; private int denom; public Fraction3YourName() { //sign = ; //denom = ; } public Fraction3YourName(int n) { //sign = ; //num = n; //denom = ; } public Fraction3YourName(int s, int n, int d) { //sign = s; //num = n; //denom = d; } } You are...
4) Define an abstract class Name Java class that implements interface Comparable   
4) Define an abstract class Name Java class that implements interface Comparable   
Goals Understand class structure and encapsulation Description Define a class Product to hold the name and...
Goals Understand class structure and encapsulation Description Define a class Product to hold the name and price of items in a grocery store. Encapsulate the fields and provide getters and setters. Create an application for a grocery store to calculate the total bill for each customer. Such program will read a list of products purchased and the quantity of each item. Each line in the bill consists of: ProductName ProductPrice Quantity/Weight The list of items will be terminated by “end”...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT