Question
Suppose you are designing a system for a grocery store where number of categories in the system is pre-defined and known but the number of
Suppose you are designing a system for a grocery store where number of categories in the system is pre-defined and known but the number of products is completely unknown. For example Category Items Juices
Pid Pname Price Quantity 101 Rani Juice 80 200 102 Tropicana 100 300 103 Sugarcane juice 40 100 104 Wheatgrass juice
150 250 105 Grapefruit juice 160 450
Soft Drinks
Pid Pname Price Quantity 201 Coca Cola 100 1000 202 Pepsi 90 1500 203 Marinda 90 500 204 Shezan 500 500 205 Sprite 90 1500 Furniture Pid Pname Price Quantity 301 Couch 150000 5 302 Bureau 800000 2 303 Wardrobe 15000 3 304 Trundle Bed 500000 1 305 Hope Chest 1500 3
Chocolat es
Pid Pname Price Quantity 401 Dairy Milk 450 10 402 Twix 80 50 403 Sneakers 80 50 404 Mars 80 100 405 Galaxy 70 20
As you know there is a limited number of Categories but number of products against each category is completely different so we need a better data structure for this problem. So, Mr. Alex has a data structure but doesnt know programming so you have to help him to code his idea. Mr. Alex says as we have limited categories and we know the number of categories so we will create an Array of size (number of Categories) and in each index of an array there will be a Linked list which will increase dynamically and will be used to store the products against each category.
To Implement Mr. Alexs idea, You have to do things listed below 1. Complete the Implementation of given class below
2. Open the file input.txt and see the format of text we have product information in the file like 101, Rani Juice, 80, 200, 1 201, Coco Cola, 100, 1000, 2 301, Couch, 15000, 5, 3 401, Dairy Milk, 450, 5, 4 The last number shows the product type 1 for Juices, 2 for Soft Drinks, 3 for Furniture and 4 for Chocolates. 3. Create a new file called DataLoader.java and in this class implement the method given below
public AList loadData()
This method will simply load the data from files and store them in the ArrayList (improted from java.util.*) weve created in the class. You have to load data from file and then create Product Objects and then finally store them in ArrayList and return the ArrayList when you are done with reading the file data. 4. Create a new file called Main.java and do things listed below a) Create a new ArrayList and then call the loadData method from DataLoader class to load the data from file. b) Sort the ArrayList using Collections.sort() method. c) Create 4 Linked Lists from the given code of AList of type Products and name them as Juices, Soft Drinks, Furniture and Chocolates d) Now traverse through all the products in ArrayList and store them into respective Alist, like the product with productType 1 will be stored in AList of Juices and product with productType 2 will be stored in AList of Drinks etc. e) Finally print all the AList youve created so far.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started