Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. SlideListNode Class Write a full-documented class named SlideListNode that wraps a Slide object to allow it to be inserted into a doubly linked-list data

image text in transcribedimage text in transcribedimage text in transcribed

2. SlideListNode Class

Write a full-documented class named SlideListNode that wraps a Slide object to allow it to be inserted into a doubly linked-list data structure. The Slide object reference should be contained in a field called data, and there should be two SlideListNode references serving as links to the previous and next SlideListNodes in the list. The class will be based on the following ADT specification:

private Slide data

private SlideListNode next

private SlideListNode prev

public SlideListNode(Slide initData)

Brief:

Default constructor.

Parameters: initData

The data to be wrapped by this SlideListNode. This parameter should not be null, since we should never have a SlideListNode with null data (remember, this class serves only as a wrapper for the Slide class).

Preconditions:

initData is not null.

Postconditions:

This SlideListNode has been initialized to wrap the indicated Slide, and prev and next have been set to null.

Throws: IllegalArgumentException

Thrown if initData is null.

public Slide getData()

Brief:

Gets the reference to the data member variable of the list node.

Returns:

The reference of the data member variable.

public void setData(Slide newData)

Brief:

Updates the data member variable with a reference to a new Slide.

Parameters: newData

Reference to a new Slide object to update the data member variable. This parameter should not be null, since we should never have a SlideListNode with null data (remember, this class serves only as a wrapper for the Slide class).

Preconditions:

newData is not null.

Throws: IllegalArgumentException

Thrown if newData is null.

public SlideListNode getNext()

Brief:

Gets the reference to the next member variable of the list node.

Returns:

The reference of the next member variable. Note that this return value can be null, meaning that there is no next SlideListNode in the list.

public void setNext(SlideListNode newNext)

Brief:

Updates the next member variable with a new SlideListNode reference.

Parameters: newNext

Reference to a new SlideListNode object to update the next member variable. This parameter may be null, since it is okay to have no next SlideListNode (this means weve reached the tail of the list!).

public SlideListNode getPrev()

Brief:

Gets the reference to the prev member variable of the list node.

Returns:

The reference of the prev member variable. Note that this return value can be null, meaning that there is no previous SlideListNode in the list. (this means weve reached the head of the list!).

public void setPrev(SlideListNode newPrev)

Brief:

Updates the prev member variable with a new SlideListNode reference.

Parameters: newPrev

Reference to a new SlideListNode object to update the prev member variable. This parameter may be null, since it is okay to have no previous SlideListNode (this means weve reached the head of the list!).

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.

3. PresentationManager Class

Write a fully-documented class named PresentationManager which creates an instance of the SlideList class and provides an interface for a user to manipulate the list by adding, removing, and editing slides. The following functionality should be provided:

public static void main(String[] args) Brief:

The main method runs a menu driven application which first creates an empty SlideList and then prompts the user for a menu command selecting the operation. The required information is then requested from the user based on the selected operation. Following is the list of menu options and their required information:

A sample menu is provided below indicating the functionality your SlideList program should support:

 F) Move cursor forward B) Move cursor backward D) Display cursor slide E) Edit cursor slide P) Print presentation summary A) Append new slide to tail I) Insert new slide before cursor R) Remove slide at cursor H) Reset cursor to head Q) Quit
any arguments you see fit. Lastly, you should provide a tostring() method that returns a printable representation of the slide and it's data members (title, duration, and bullets). - public static final int MAX_BULLETS =5 - private string title - private string[] bullets - private double duration - publia Slide() - Brief: - Default constructor. - This object has been initialized to an empty slide (tit1e and all bu1lets are nu11, duration =0.0 ) - You may create a custom constructor which takes arguments if you wish. - public string getTitle() - Brief: - Public getter method for the title member variable. - The title of the slide. - public void setTitle (String newtitle) - Brief: - Public setter method for the title member variable. - Parameters: - newtitle The new title of this slide. This parameter should not be nu11 - Preconditions: - Throws: - IllegalArgumentexception. - Thrown if newTitle is nu1l. - public double getDuration() - Brief: - Public getter method for the duration member variable. - The duration of the slide. - public void setDuration(double newDuration) - Brief: - Public setter method for the duration member variable. - Parameters: - public void setDuration (double newDuration) - Brief: - Public setter method for the duration member variable. - Parameters: - newDuration - The new duration of this slide. This parameter should be greater than 0 . - Preconditions: - newDuration is greater than 0 . - Throws: - IllegalArgumentException - Thrown if newDuration is less than or equal to 0 . - publia int getNumBullets() - Brief: - Gets the total number of bullet point in the slide. - Returns: - The number of bullet points in the slide. - This method counts the number of non-null elements in the bullets array. - publia string getBullet(int i) - Brief. - Gets the bullet point at index i. - Parameters: - i - The index to retrieve from the array. This value must be between 1 and MAX_BULLETS, inclusive. - Preconditions: - 1i MAX_BULLETS. - Returns: - The string representing the bullet point at the given index (may be nu1l, meaning there is no bullet point at this index). - Throws: - IllegalArgumentException - Thrown if i is not in the valid range. - publia void setBullet(String bullet, int i) - Brief. - Parameters: - bullet - The string to place as the ith bullet point in bullets. This parameter may be null, indicating that the bullet at index i is to be erased from the slide. - i. The index to place builet in the array. This value must be between 1 and MAX_BULLETS, inclusive. - Preconditions: - 1i MAX_BULLETS. - Postconditions: - The bullet point at index i has been updated to the string bullet. - There are no holes in the bullets arrav. All bullet points occupv the lowest possible indices of the arrav

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions