Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CpE 207L Data Structures Lab In this project, you are asked to use Hash Table to store Product information for a Store. The program allows

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

CpE 207L Data Structures Lab In this project, you are asked to use Hash Table to store Product information for a Store. The program allows you to supplement the Store with additional new Products. The Product information includes the following: String supplier Address // in this form: area_block_street_building phone int id //product id consists of 4 digits String productName double price You need to write and submit a java program that includes three classes: Product.java, Store.java and Test.java. 1) Class Product Instance variables: private String supplierAddress; private int id; private String productName; private double price; Methods: A constructor that initializes the instance variables. Set and get methods for each instance variable. toString method that returns a string containing supplierAddress, id, productName and price. 2) Class Store Instance variables: private Product table[]; private int size; // Hash table // Hash table size Methods: public Store(int size) Create an array of Products and save the size of the hash table. public int hashFun(String supplier Address, int id) Split the supplier Address string, based on underscore. Then, find the hash value according to the following steps: 1. Take the first character of the area, block, street, building and phone 2. Convert them to ASCII. 3. Cast them into int. 4. Add each value with power of 3 (340, 3-1,3-2, 3-3) accordingly. 5. Add the result to the product id. 6. Finally return (result) % table size to get the hash value. public boolean insert(Product p) Insert the product p in the proper location and return true. When a collision happens, use quadratic propping. If the hash table is full, return false. Note: duplication is not allowed. public void printTable Call toString() method and print the contents of the Hash Table in a readable way. public int suppliers Count and return number of suppliers that deal with the store. public void maxPrices() print the product with the maximum price for each supplier. public boolean deletProduct(String supplierAddress, int id) Search the hash function and delete product the has the given attributes (supplierAddress, id). 3) Class Test In the main method, create an object of class Store with size 11. Display a menu of choices, as shown in the sample output. Add your sample output as a comment at the end of the test class. Sample output: 1. Insert product 2. delete product 3. Print all products 4. Count the number of suppliers. 5. Print product with max price per each supplier 6. Exit Enter your choice: 1 Insert the following supplier address (area_block_street_building_phone format) or Q to exit: Salmiya_11_22_33_4444 product id: 1234 product name: p1 product price: 20.5 supplier address (area_block_street_building_phone format) or Q to exit: Salmiya_11_22_33_4444 product id: 2234 product name: p2 product price: 40.8 supplier address (area_block_street_building_phone format) or Q to exit: Hawali_11_22_33_4444 product id: 3234 product name: p3 product price: 10.5 supplier address (area_block_street_building phone format) or Q to exit: Hawali_11_22_33_4444 product id: 4234 product name: p4 product price: 5.7 supplier address (area_block_street_building_phone format) or Q to exit:Q 1. Insert product 2. delete product 3. Print all products 4. Count the number of suppliers. 5. Print product with max price per each supplier 6. Exit Enter your choice: 3 Supplier Product id Salmiya_11_22_33_4444 1234 Salmiya_11_22_33_4444 2234 Hawali_11_22_33_4444 3234 Hawali_11_22_33_4444 4234 Product name pl Product price 20.5 40.8 10.5 P2 p3 P4 5.7 1. Insert product 2. delete product 3. Print all products 4. Count the number of suppliers. 5. Print product with max price per each supplier 6. Exit Enter your choice: 4 There are 2 different suppliers. p3 1. Insert product 2. delete product 3. Print all products 4. Count the number of suppliers. 5. Print product with max price per each supplier 6. Exit Enter your choice: 5 The product with maximum price by Supplier: Salmiya_11_22_33_4444 is Product id Product name Product price 2234 p2 40.8 The product with maximum price by Supplier: Hawali_11_22_33_4444 is Product id Product name Product price 3234 10.5 1. Insert product 2. delete product 3. Print all products 4. Count the number of suppliers. 5. Print product with max price per each supplier 6. Exit Enter your choice: 2 supplier address (area_block_street_building phone format) or Q to exit: Salmiya_11_22_33_4444 product id: 1234 DELETED! supplier address (area_block_street_building_phone format) or Q to exit: Salmiya_11_22_33_4444 product id: 1234 NO EXIST! supplier address (area_block_street_building_phone format) or Q to exit: Q Product name p2 1. Insert product 2. delete product 3. Print all products 4. Count the number of suppliers. 5. Print product with max price per each supplier 6. Exit Enter your choice: 3 Supplier Product id Salmiya_11_22_33_4444 2234 Hawali_11_22_33_4444 3234 Hawali_11_22_33_4444 4234 1. Insert product 2. delete product 3. Print all products 4. Count the number of suppliers. 5. Print product with max price per each supplier 6. Exit Enter your choice: 6 Thank you! Product price 40.8 10.5 5.7 p3 p4

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

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions