Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a new class types: CountryList You are to write a class called CountryList, which is holds linked list of CountryNode objects, that can store

Define a new class types: CountryList

You are to write a class called CountryList, which is holds linked list of CountryNode objects, that can store as many objects as the user might want to add to it. Your class must at minimum contain the following methods.

Methods:

A constructor that creates an empty CountryList object.

A method add() that takes a Country object as parameter and adds that new object to the end of the list. A method getIndex() that takes a int as parameter. If the index is valid, returns a Country object. Otherwise if the requested index < 0 or index >= the size of the list, then throw an IndexOutOfBoundsException.

A method contains that takes a Country object as parameter and checks if the name of the country can be found in the list. That means, we will assume that Country objects are equal if their names are equal. Note: to check whether object foo of type Country equals objects bar of type Country, you must override the equals() method in class Country.

A method toString() which returns a string containing information about every country in the list. Note: A node should not be responsible for printing another node's data. Submitting a recursive solution where each node print's another's data will be considered incomplete. Instead, the linked list should be responsible for traversing all the nodes and printing each one. Extra Credit Opportunity:

For four extra credit points, implement the method:

insertAtIndex() that takes two arguments, a Country object (similar to the add() method) and an int parameter called index. This method will insert the country at the location specified by index.The user may request an index that is out of bounds:

If the requested index < 0, then throw an IndexOutOfBoundsException \.).

If the user requests an index > the size of the list, then we will assume the user misjudges the length of the list. So, add the element to the end of the list.

To get you started I've listed the cases to consider:

Insert at the beginning. Insert in the middle (of two non-null nodes).

Insert at the end.

Hint: If we call the new node, newGuy. It might be easier to keep track of two references: a prev reference for the node that comes before our newGuy; and after for the node that comes after newGuy.

To receive extra credit, this method must be included with your implementation and thoroughly tested with output in your RUN file. So, what do we mean by thoroughly tested? Well, for example there are three cases (that I've listed above), so include at least three test cases for this part alone. >Include the extra credit portion along with the rest of your implementation in your assigned repository. Note: Late submission penalty applies to extra credit portion as well.

I already have Class Country and other neccessary class, but this one I dont know how to do it . Really need help, Thank you.

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago