Data Structure Assignment: Designing A Grocery Store Chain
Question
Task:
CASE STUDY:
This data structure assignment is an individual report about the design of an OOP system using data structures and algorithms.
A grocery store chain intends to computerize their records. The grocery chain has 4 types of product categories, dedicated to food, health, dairy, and meat. Out of these categories, food category has 300 products, both dairy and health has only 50 products, and meat has 100 products. For all the categories, the system needs to store the barcode, use by date, price, quantity in hand, quantity to be ordered and the aisle location.
For inventory and audit purpose, the system should also have option of logging the expired products and then should be able to generate the reports. The team members should also be able to search for a particular product, check the quantity or location of the product and should also be able to sort the list on various parameters.
You need to decide how would you like to represent different products and categories. For each of these decide what variables should be there (think in terms of OOP design). Also provide ranges for these variables. You will need to specify keys as well to carry out some essential operations related to grocery shop management. Identify and list down potential keys for given entities. Also use your experience of grocery shopping from any supermarket, and list various operations which you think the system should support. Along with the operations, describe the algorithms which you will use for those operations and give your justification for choosing the algorithm.
Now assume that in coming years the grocery store chain has grown exponentially and has increased its range of products. In food category, it has around 4000 products from different vendors, health has 2500 products, dairy has 1000 and meat product range has increased to 1000.
What changes you will bring in the design of the system to make sure the system works efficiently?
Answer
Executive Summary
Object-Oriented Programming (OOP) involves organising software design around data structures, objects, or algorithms. This data structure assignment evaluates the efficiency and effectiveness of data structures and algorithms used for designing a grocery store chain. After implementing the data structures and algorithms, the efficiencies are justified with reason. The report also focuses on accessing and applying suitable recursive data structures and algorithms to IT systems and applications designed for the grocery store. The operation of the program, the use of algorithms are discussed with proper justification. The report talks about modifications that need to be done to increase the efficiency of the system.
Introduction
Object Oriented Programming (OOP) involves organising software design around data structures, objects, or algorithms. OOP involves programming for manufacturing and design for software and IT applications. With the help of certain data structures and algorithms, an OOP application can be designed in Java (Mahoney, 2021). This report evaluates the efficiency and effectiveness of data structures and algorithms used for designing a grocery store chain. After implementing the data structures and algorithms, the efficiencies are justified with reason. The report also focuses on accessing and applying suitable recursive data structures and algorithms to IT systems and applications designed for the grocery store. As the grocery store has exponentially grown and the products range increased with 400 products in the food category and 2500 in health, 1000 in dairy and 1000 in meat, there is a need for an effectively working system that holds the data and help staff access to the information of the products.
Background
Object-Oriented Programming is an advanced solution to modern application design and implementation as explained in Somashekara, et al. 2017. In this case, OOP in Java has been used to write a system that manages a grocery store with exceptionally growing inventories and store chains. The initial store inventory is recorded in a text file that must be read in the code. This project emphasizes a grocery store chain. There are four types of product categories in this grocery chain. Those are dairy, meat, food, and health. In the food category, there are 300 products and in the meat category, there are 100 products. Whereas there are 50 products in both the health and dairy category. Intending to computerize its records, the grocery chain needs to record the essential information such as price, barcode, quantity, etc. For this purpose, the company is designing an OOP system. To computerize the whole process, there is a need for some pre activities. Generating reports can be done after recording the expired products. There is also a need of searching for the product, quantity, or location checking of the product, and sort listing them. In terms of OOP design, there is a need for a specific representation of different products and categories (Sedgewick and Wayne, 2017). There are variables with ranges for this specification. Essential operations of the shop’s management are specified. The grocery shop chain’s potentialities are identified and described. Various operations in supermarkets that the OOP system must support are noticed and explained. There are justifications for choosing algorithms for those operations. The OOP system is designed assuming that the company will expand the number of products in near future (Dageförde and Kuchen, 2019).
Case Study and the Design
Variables, Ranges and Keys
The Java code helps the system in storing inventory, processing the orders for meat, dairy, etc and tracking the items that are out of stock. In this case, two algorithms, Insertion Sort and Bubble Sort have been used along with Java Classes that are relevant for grocery store management. In this case, a number of classes have been used to carry out the code in Java, namely, GroceryManager, GroceryOrder, GroceryItem, Diary – a subclass of GroceryItem, Produce – a subclass of GroceryItem, Meat- a subclass of GroceryItem, groceryException and GroceryDriver that contains packages for the grocery store. The driver has the purpose of reading inventory from the text file for the store, printing them and reading the orders and processing the orders of the store. The Driver also helps in sorting the name, price, and restocking list of the inventory.
A data structure can be imagined as a store of data on a computer where data are organized and accessed efficiently. To maintain complex data there is a need for a data structure to enhance the performance of the program (Tanielu, et al. 2019). There are different types of data structures that organize data in different ways for example list, stack, array, queue, etc. It is very important to choose the appropriate data structure for the project. The concepts that are used in this are Inheritance, Generics, and Exception handling. Inheritance is the mechanism of basing one object or class upon another object which is also known as a prototype-based inheritance in OOP (Abidin and Zawawi, 2020). Here, inherited classes are Meat, Dairy, and products which are subclasses of GroceryItem parent class. Generics in Object-Oriented Programming helps in defining a specification of the class that goes with any kind of data type. Exception handling is used as a mechanism of centralised processing of errors and handling exceptional situations in the program (Tanielu, et al. 2019). In this case, an exception has been used several times for excluding items in GroceryException. The final code can be executed successfully by removing errors through Exception Handling.
Operations and the Justifications
The operation is handled by OOP in Java that designed the required system with the help of several classes in Java and read data from the text file that contains the item list. Apart from that Bubble Sort and Insertion Sort are used to shortlist the required items and find out new inventories in the grocery list.
The operation is carried out by Driver.Java which is a package to read inventory from the text file for the store, print them and read the orders and process the orders of the store. The Driver also helps in sorting the name, price, and restocking list of the inventory.
The GroceryItem.Java is an abstract class that implements comparable and holds things like milk, butter and bread which are the price of each. It also keeps track of the items in the list that are restocked in the store and counts their quantity. Several public methods are used in this case, such as void setName, string getName, etc.
The subclasses Diary.Java, Produce.Java, and Meat.Java operate under the parent class GroceryItem that holds specific information about the subclasses. When there is an operation under the parent class, the operations in the subclasses get interlinked. The values and keys change accordingly. The constructor used here take input that has been read from the text file and changes it according to the operations carried out by the parent class. Diary has several public interfaces like void setRefrigerator that operates the temperature and int getRefrigerator that shows the temperature. Produce has public interfaces like Boolean getsOrganic and Meat has interfaces like Boolean getsGround.
In this case, Java ArrayList has been used to read the text files in form of arrays and operate within the program. The program shows the name of the produce, its quantity and price and the temperature if required. It also shows if the product is organic or not.
The output of the code is shown below.
Produce.Java
Meat.Java
Diary.Java
Algorithms and the justifications
In the case of programming for the grocery store, the inventories are changing as restocking is happening. Apart from that, the company is assuming that in the coming years, the store chain has grown exponentially and has increased its range of products. In each category, the products are added every year. So, there is a need for sorting algorithms to find the exact required product when dealing. In this case, Insertion Sort and Bubble Sort can be used. The justification for using such sorting algorithms in the program is discussed here.
Insertion sort is a sorting algorithm based on the comparison that helps in comparing the price and other features of the grocery items. It is mainly suitable for small data sets like the one used in the grocery store at first. Practically, its possible area of implementation is wide. Products that are randomly arranged rearranging them in ascending order according to the price is an example of insertion sort. Items sorting is another example that is seen here while receiving orders. Insertion sort has an array that has two lists at each point. The two lists are partially sorted and unsorted. So, the array is virtually split into two parts- sorted and unsorted. Every time an item is picked up from the unsorted list and placed in the partially sorted list (Tanielu, et al. 2019). This is called insertion because the elements are inserted at the correct position in a sorted list from an unsorted list. Insertion sort is a stable algorithm. After performing sorting duplicate elements orders are preserved. For using insertion sort data must be already sorted. So that it takes less execution time as compared to others sorting techniques. Insertion sort does not require all the elements every time it works. So, there is no need for all the data initially. It is suitable for the grocery chain where data will arrive from time to time (Mohammed, et al. 2017). It is important to arrange steps according to the working process of insertion sort which is explained through this algorithm.
Step 1: When the first element will be chosen then it will be taken as sorted. So, return 1.
Step 2: The next element will be picked.
Step 3: All the elements in the sorted list will be compared.
Step 4: All the elements will be shifted in the shorted list that is greater than the value to be sorted.
Step 5: The value will be inserted.
Step 6: This process will be repeated until the list will completely be sorted.
Insertion Sort Algorithm is described below.
insertionSort(array)
mark first element assorted
for each unsorted element X
'extract' the element X
for j <- lastSortedIndex down to 0
if current element j > X
move a sorted element to the right by 1
break the loop and insert X here
end insertionSort
Bubble sort is an algorithm that sorts two adjacent values. The algorithm swaps those values up to the time when they are in the expected order. It is called the bubble sort because as the air bubbles move up in the water to the surface, the values of the array move to the ending in each repetition. Let the values of an array be sorted in ascending order. In the iteration, the first step will be comparing the first and second elements. If the second element will be smaller than the first element, then in the second step they will be swapped. In the third step, the second and third elements will be compared and if they are in disorder, they will be swapped. In this way, the process will be going on up to the last element. The same process will go on for the remaining values. After every iteration among the unsorted values, the largest value will be placed at the end of the array. After all the unsorted values are placed at their right position, the array will be sorted (Guo and Lu, 2016). Bubble sort helps in arranging the items in the array and reading them as per the requirement of the store for which it has been used in this case. The bubble Sort Algorithm is described below.
bubbleSort(array)
for i <- 1 to indexOfLastUnsortedElement-1
if leftElement > rightElement
swap leftElement and rightElement
end bubbleSort
Modifications
As the experience of grocery shoppers are changing every day, it is important to make the system works efficiently. There is a need for modification in the system that will allow it to work efficiently. While designing the OOP system, it is important to make sure that our products are arranged in a proper manner as an array that is readable and flexible to handle. Java-built in array list can be used. Apart from that, there is a need for error removal that is not happening here with exception handling. It is recommended to use debugging of the code for better performance. The use of abstract methods in the GroceryItems in a more effective way can be done to increase the efficiency of the code. It is also important to modify the interface of the system so that it becomes more user friendly for the staff.
Conclusion
With the help of concepts of inheritance, generics and Exception handling, a Java program has been created for the grocery store. With the use of HashSet and algorithms like Insertion Sort and Bubble Sort, this system can be designed and implemented. The data is read from data files form of text files that contain arrays of grocery lists. The operation of the program is discussed with proper justification. The report also talks about modifications that need to be done to increase the efficiency of the system.
References
Abidin, Z.Z. and Zawawi, M.A.A., (2020). OOP-AR: Learn Object Oriented Programming Using Augmented Reality. International Journal of Multimedia and Recent Innovation, 2(1), pp.60-75.
Dageförde, J.C. and Kuchen, H., (2019). A compiler and virtual machine for constraint-logic object-oriented programming with Muli. Journal of Computer Languages, 53, pp.63-78.
Guo, J. and Lu, M., (2016). The extra connectivity of bubble-sort star graphs. Theoretical Computer Science, 645, pp.91-99.
Mahoney, M., (2021). Object-Oriented Programming.
Mohammed, A.S., Amrahov, ?.E. and Çelebi, F.V., (2017). Bidirectional Conditional Insertion Sort algorithm; An efficient progress on the classical insertion sort. Data structure assignment Future Generation Computer Systems, 71, pp.102-112.
Sedgewick, R. and Wayne, K., (2017). Introduction to programming in Java: an interdisciplinary approach. Addison-Wesley Professional.
Somashekara, M.T., Guru, D.S. and Manjunatha, K.S., (2017). Object Oriented Programming with Java. PHI Learning Pvt. Ltd..
Tanielu, T., 'Akau'ola, R., Varoy, E. and Giacaman, N., (2019), May. Combining analogies and virtual reality for active and visual object-oriented programming. In Proceedings of the acm conference on global computing education (pp. 92-98).