Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question is of course 'Data Structure and Algorithms '. Write the code for the given question in java language and do it as directed.

This question is of course 'Data Structure and Algorithms '. Write the code for the given question in java language and do it as directed.

image text in transcribed

Question 1 (5+10+5+5+15) 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 150 250 juice 105 Grapefruit juice 160 450 Soft Pid Pname Price Quantity Drinks 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 Pid Pname Price Quantity es 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 doesn't 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. Alex's idea, You have to do things listed below 1. Complete the implementation of given class below cinterface Comparator Sort the Products with Quantity Product - id: int - name: String - price: double - quantity: int - productTypeint + Constructors + Getters + Setters toString 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.*) we've 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 product Type 1 will be stored in AList of Juices and product with product Type 2 will be stored in AList of Drinks etc. e) Finally print all the AList you've created so far

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

Students also viewed these Databases questions

Question

LO2 Compare three types of individual incentives.

Answered: 1 week ago