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.
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.
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”...
Using Union technique, define two structs employee_record and student_record. The employee_record struct will contain the name...
Using Union technique, define two structs employee_record and student_record. The employee_record struct will contain the name (size 50) and the salary (double) of an employee. The student_record struct will have the name (size 30), Id number (int) of a student, and the grade (int). Include these two structs in a union called 'person'. Using file redirection called input.txt, at first, ask the user for the employee's information and print them from the main() and the size of the union. Then...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size 3x3 as private member.        There should be two public methods within the class definition namely: void setMatrixValue(int i, int j); that should set m[i][j] with user defined values int getMatrixValue(int i, int j); that should return m[i][j] Make a global function named ‘CrossProduct(Matrix m1, Matrix m2)’ that should compute the marix multiplication
A study showed that 62% of supermarket shoppers believe supermarket brands to be as good as national name brands.
  A study showed that 62% of supermarket shoppers believe supermarket brands to be as good as national name brands. To investigate whether this result applies to its own product, the manufacturer of a national name-brand ketchup asked a sample of shoppers whether they believed that supermarket ketchup was as good as the national brand ketchup. (a) Formulate the hypotheses that could be used to determine whether the percentage of supermarket shoppers who believe that the supermarket ketchup was as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT