Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A company would like to implement its catalog of producst as a linked list, called ProductList. 1. Write a Product node class, called ProductNode, to

A company would like to implement its catalog of producst as a linked list, called ProductList. 1. Write a Product node class, called ProductNode, to hold the following information about a Product: code (as a String) name (as a String) price (as double) ProductNode should have constructors and methods (getters, setters, and toString()) to manage the above information as well as the link to next node in the list. 2. Write the ProductList class to hold objects of the class ProductNode. This class should define: Two instance variables head and size. (size should be updated with insertions and removals from the list) The constructor of the class is: public ProductList(){ head = null; size = 0; } The ProductList class should implement the following interface List // a list interface public interface List { public boolean isEmpty(); // returns true if the list is empty, false otherwise public int listSize(); // returns the number of items in the list public ProductNode get(int index); //returns the ProductNode object at the specified index or null if the list is empty public void addFirst(ProductNode item); // adds a product at the front of the list public void addLast(ProductNode item); // adds a product at the end of the list public ProductNode search(String code); // search and return the product with the given code public ProductNode[] searchPriceGreaterThan(double p); //search and return an array of the set of ProductNode items // having a price greater than p public void add(int index, ProductNode item); // adds a product to the list at the given index public String remove(int index); // removes the product from the list that has the given index public String remove(ProductNode item); // removes the first item in the list whose data equals // the given item data public void removeDuplicates(); // removes the duplicates of every product in the list (nodes with the same data) @Override public String toString(); // implement a toString() method that prints the list in the // format: //[ size: the_size_of_the_list // product1, // product2, //.... ] } 3. Write a TestProductList class to test the class ProductList. This class should have a main method in which you perform the following actions: Create a ProductList object, Insert 10 ProductNode objects into the created Product List, Print the content of your Product list, Find out in the list the items that have a price greater than 100. Print them out. Remove the first element of the list Remove the item at index 5 Print again the content of your Product list, Insert some duplicate products in the list Print again the content of your Product list, Remove duplicates Print again the content of your Product list, For each operation above, print a small message that describes the operation you are doing. For example: System.out.println(Insertion of 10 products in the list); Make sure your ProductList class implements the interface as specified, i.e. your class should begin with public class ProductList implements List.

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 Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions