Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA 3. SlideList Class Write a fully-documented class named SlideList which implements a double linked-list data structure. The SlideList should maintain a list of

IN JAVA

3. SlideList Class

Write a fully-documented class named SlideList which implements a double linked-list data structure. The SlideList should maintain a list of Slides by chaining a series of SlideListNodes between a head and a tail reference. In addition, a cursor should be provided to allow a user to traverse the list, selecting individual SlideListNodes to allow for insertion, deletion, and manipulation of the Slides they contain. Lastly, the class should provide methods to query information about the list, such as its size, the total duration of all Slides in the list, and the total bullet points of all Slides in the list.

private SlideListNode head

private SlideListNode tail

private SlideListNode cursor

public SlideList()

Brief:

Default constructor which initializes this object to an empty list of Slides.

Postconditions:

This SlideList has been initialized with head, tail, and cursor all set to null.

public int size()

Brief:

Returns the total number of Slides in the slideshow.

Returns:

The count of all Slides in the slideshow.

Note:

This method should run on O(1) time.

public double duration()

Brief:

Returns the total duration of the slideshow.

Returns:

The sum of all individual Slide durations in the slideshow.

Note:

Depending on the implementation, this method may run in O(1) or O(n) time. both will be accepted..

public int numBullets()

Brief:

Returns the total number of bullet points in the slideshow.

Returns:

The sum of all bullet points of all individual Slides in the slideshow.

Note:

Depending on the implementation, this method may run in O(1) or O(n) time. both will be accepted..

public Slide getCursorSlide()

Brief:

Gets the reference to the Slide wrapped by the SlideListNode currently referenced by cursor.

Returns:

The reference of the Slide wrapped by the SlideListNode currently referenced by cursor. If the cursor is null, then this method should return null as well (i.e. the cursor does not reference a Slide).

public void resetCursorToHead()

Brief:

Returns the cursor to the start of the list.

Postconditions:

If head is not null, the cursor now references the first SlideListNode in this list.

If head is null, the cursor is set to null as well (there are no Slides in this list).

public void cursorForward()

Brief:

Moves the cursor to select the next SlideListNode in the list. If the cursor is at the tail of the list, this method throws an exception (this includes the case where cursor and tail are both null).

Throws: EndOfListException

Thrown if cursor is at the tail of the list.

public void cursorBackward()

Brief:

Moves the cursor to select the previous SlideListNode in the list. If the cursor is at the head of the list, this method throws an exception (this includes the case where cursor and head are both null).

Throws: EndOfListException

Thrown if cursor is at the head of the list.

public void insertBeforeCursor(Slide newSlide)

Brief:

Inserts the indicated Slide before the cursor.

Parameters: newSlide

The Slide object to be wrapped and inserted into the list before the cursor.

Preconditions:

newSlide is not null.

Postconditions:

newSlide has been wrapped in a new SlideListNode object

If cursor was previously not null, the newly created SlideListNode has been inserted into the list before the cursor.

If cursor was previously null, the newly created SlideListNode has been set as the new head of the list (as well as the tail).

The cursor now references the newly created SlideListNode.

Throws: IllegalArgumentException

Thrown if newSlide is null.

Warning

You should NOT move data references around between SlideListNodes to accomplish this method. Instead, you should wrap the newSlide object in a new SlideListNode object, and insert this object into the list before the cursor.

public void appendToTail(Slide newSlide)

Brief:

Inserts the indicated Slide after the tail of the list.

Parameters: newSlide

The Slide object to be wrapped and inserted into the list after the tail of the list.

Preconditions:

newSlide is not null.

Postconditions:

newSlide has been wrapped in a new SlideListNode object

If tail was previously not null, the newly created SlideListNode has been inserted into the list after the tail.

If tail was previously null, the newly created SlideListNode has been set as the new head of the list (as well as the tail).

The tail now references the newly created SlideListNode.

Throws: IllegalArgumentException

Thrown if newSlide is null.

Note:

This insertion method does not affect the cursor, unless the list was previously empty. In that case, head, tail, and cursor should all reference the new SlideListNode.

public Slide removeCursor()

Brief:

Removes the SlideListNode referenced by cursor and returns the Slide inside.

Preconditions:

cursor is not null.

Postconditions:

The SlideListNode referenced by cursor has been removed from the list.

All other SlideListNodes in the list exist in the same order as before.

The cursor now references the previous SlideListNode (or the head, if the cursor previously referenced the head of the list).

Returns:

The reference to the Slide contained within the SlideListNode which was just removed from the list.

Throws: EndOfListException

Thrown if cursor is null.

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Assess the requirements for strategic LMD

Answered: 1 week ago

Question

Solve for x: 2(3x 1)2(x + 5) = 12

Answered: 1 week ago