Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSBP 319 Data structures - Linked Lists - USE JAVA (NetBeans) A company would like to implement its inventory of computing machines as a linked

CSBP 319 Data structures - Linked Lists - USE JAVA (NetBeans)

A company would like to implement its inventory of computing machines as a linked list, called ComputerList.

  1. Write a Computer node class, called ComputerNode, to hold the following information about a Computer:

code (as a String) brand (as a String) model (as a String) price (as double) quantity (as int)

ComputerNode 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.

  1. Write the ComputerList class to hold objects of the class ComputerNode. This class should define:

Two instance variables head and size. (size should be updated during insertions and removals from the list)

The constructor of the class is: public ComputerList(){ head = null; size = 0; }

The ComputerList class should implement the following interface:

public interface CList { public boolean isEmpty(); // returns true if the list is empty, false otherwise

public int listSize(); // returns the number of items in the list

public ComputerNode getAt(int index); //returns the ComputerNode object at the specified index or null if the list is empty

public void addFirst(ComputerNode item); // adds a Computer at the front of the list

public void addLast(ComputerNode item); // adds a Computer at the end of the list

public void addAt(int index, ComputerNode item); // adds a Computer to the list at the given index

public ComputerNode search(String code); // search and return the Computer with the given code

public ComputerNode[] searchPriceGreaterThan(int p); //search and return an array of the set of ComputerNode items //having a price greater than p

public String removeAt(int index); // removes the Computer from the list that has the given index

public String remove(ComputerNode item); // removes the first item in the list whose data equals // the given item data

public void removeDuplicates(); // removes the duplicates of every Computer 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 // Computer1, // Computer2, //.... ] }

3.Write a TestComputerList class to test the class ComputerList. This class should have a main method in which you perform the following actions:

Create a ComputerList object,

Insert 10 ComputerNode objects into the created Computer List,

Print the content of your Computer list,

Find out in the list the items that have a price greater than 3000. Print them out.

Remove the first element of the list

Remove the item at index 3

Print again the content of your Computer list,

Insert some duplicate Computers in the list

Print again the content of your Computer list,

Remove duplicates

Print again the content of your Computer list,

For each operation above, print a small message that describes the operation you are doing. For example: System.out.println(Insertion of 10 Computers in the 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

More Books

Students also viewed these Databases questions