Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab, you will implement a array-based list of words (Strings). You are given a List interface and an implementing WordList class has been

In this lab, you will implement a array-based list of words (Strings). You are given a List interface and an implementing WordList class has been created, but the constructors and methods need to be implemented. In addition, a new Exception class, WordListFullException, will need to be created and used.

Download the starting code project here:

Driver.java Download Driver.java

WordList.javaDownload WordList.java

adding to the beginning of a chain of linked nodes

removing the first linked node

adding to the end of a chain of linked nodes

removing the last linked node

iterating through all linked nodes

Notes about this linked-node-based implementation:

Order is important

Duplicates are allowed

Many methods try to give back useful information in their return statements. Some examples that might not be intuitive:

add("cat") will return a boolean for whether or not the add was successful

remove("cat") will return a boolean for whether or not the remove was successful

remove(3) will return the string in position 3

set(5, "cat") will change the string in position 5 to "cat" and return the word that used to be in that position

We should expect exceptions to be thrown when a parameter value does not make sense. In this case, the only parameter might be bad is if the index for an operation is out of bounds.

Notes about an array-based implementation:

In this lab, the array size is fixed. That means, there is a maximum size, and if we reach that size, we cannot add any additional elements. If the client tries to add to a full list, a WordListFullException is thrown.

There is a difference between the size of the list, and the length of the array. The length of the array never changes in our implementation. But the size does. When the size of the list is equal to the length of the array, we know that the list is full.

If an operation is attempted when the specified index is out of bounds, throw an IndexOutOfBoundsException.

When items are added to the list, it may be necessary to shift other items to the right.

When items are removed from the list, it is important to set unused locations in the array to null. The reason this is important is for proper memory management. We don't want unneeded references to point to objects that are no longer in the list. This allows for proper "garbage collection" in Java. So

Each remove() method, if successful, should set one memory location to null.

The clear() method should set all locations to null.

The purpose of toArray() is to give back a newly created array of only the items in the list. It is not supposed to give back the array instance variable.

Instructions:

Download WordList.java and Driver.java to your Eclipse Project

Implement and test all constructors and methods. A suggested starting order:

Both constructors

add() - The version that takes just a String parameter

toArray() - Makes it easy to see how your methods are working

contains(), size(), clear() - These should be easy to implement

The rest of the methods, testing as you go.

Test thoroughly. Pay careful attention to edge cases:

What happens when you add to a full array?

What happens when you remove from an empty list?

When things seem to be working properly submit to to Canvas as described below.

Very briefly describes:

What was learned/interesting/useful

Outstanding questions

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

Explain the importance of nonverbal messages.

Answered: 1 week ago

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

Prepare an employment application.

Answered: 1 week ago