Repository link: https://github.com/CSE-116/ProblemSet-3
To submit your project, run problem.Zipper, which will create a zip file containing the
problem set, and submit it to Autolab.
For this problem set, you will implement a media library that uses polymorphism, static methods on binary
trees in problem.ProblemSet3, and JUnit tests. Unless noted otherwise, methods are public
and non-static.
The problem.Media abstract class is provided to you in its entirety. Do not make any changes to this class.
Song (Testing: 3 points, Implementation: 2 points): The problem.Song class is provided in the starter code. It extends
Media and includes a constructor and the methods play, pause, and
getPlaybackTime, all of which function properly and do not need to be edited.
However, the provided advancePlaybackTime method contains multiple bugs that need to be fixed.
The expected behavior of advancePlaybackTime is as follows:
isFinished
instance variable to true
advancePlaybackTime from Media
Chapter (Testing: 3 points, Implementation: 2 points): Create a class in the problem package named Chapter.
A chapter represents a named segment of an audiobook with a duration. This class should implement the
following methods:
getName, setName, getDuration, and setDuration
Audiobook (Testing: 5 points, Implementation: 5 points): Create a class in the problem package named
Audiobook that extends Media. An audiobook plays a sequence of chapters in order.
This class should implement the following methods:
play,
pause, and getPlaybackTime with the same functionality as
the Song class
setPlaybackSpeed: Set the playback speed of the audiobook. Playback speed should
initially be 1.0. The playback speed cannot be set to a value less than 0.5 or greater than 4.0.
If the playback speed is set to a value less than 0.5 or greater than 4.0, it should be set to the
nearest valid value (0.5 or 4.0)
advancePlaybackTime: When playing, advance playback according to the audiobook's
playback speed. The parameter of this method is the amount of real time that has passed and the
playback time should advance by this amount times the playback speed. If playback reaches or
passes the end of the book, cap playback time at
the total length and mark the audiobook as finished. Note that the duration of the book
is the sum of the duration of all its chapters. This method must override the
advancePlaybackTime method inherited from the Media class
getCurrentChapterName: Return the name of the chapter currently being played, based on
playback position and chapter lengths. If the book is finished, return the name of the last chapter.
You may assume the book has at least 1 chapter (in your tests, always give your test books at least 1 chapter)
getTitle: Return a title that reflects both the current chapter and the book title. The format should
be currentChapterName - bookTitle. That is a space, a dash, then another space ( - ) between
the chapter name and book title. This method must override the getTitle method inherited
from the Media class
Playlist (Testing: 5 points, Implementation: 5 points): Create a class in the problem package named
Playlist. This class should implement the following methods:
populatePlaylist: This method takes an ArrayList of Songs and an ArrayList of Audiobooks and
should add all songs and audiobooks to the playlist
getMediaSortedByTitle: Return a new ArrayList of Media containing
every item in this
playlist, sorted by each item's getTitle() value. Comparisons should be case-insensitive
(sort alphabetically ignoring capitalization)
The last part of this problem set is to complete static methods in the problem.ProblemSet3
class, all of which are related to binary trees.
maxBST (Testing: 5 points, Implementation: 5 points): In the problem.ProblemSet3 class, complete the
maxBST method, which takes a BST of Integers and returns an
int. This method returns the maximum value in the BST according to that BST's
Comparator
Comparator. It is not necessarily the largest numeric value in the tree
BST is empty (the root is null), return 0
maxBinaryTree (5 points. No testing required): In the problem.ProblemSet3 class, complete the
maxBinaryTree method, which takes a BinaryTreeNode of Integers and an
Integer Comparator, and returns an int. This method returns the
maximum value in the binary tree rooted at the given node, according to the comparator
null), return 0
isBST (5 points. No testing required): In the problem.ProblemSet3 class, complete the
isBST method, which takes a BinaryTreeNode of Integers and an
Integer Comparator, and returns a boolean. Return true if
the tree rooted at the given node is a valid BST under that comparator, and false otherwise
Write tests for the parts of the specification
described below in the tests.TestProblemSet3 class. You are encouraged to write tests before you implement each
part. If a test fails, use the debugger to find and fix your bug.
Song
Song.advancePlaybackTime method. Your tests should fail on the buggy
starter implementation, and on any implementation that does not match all the expected behavior
Song class that were provided in the
handout code
Chapter
Chapter class. Your tests should cover construction, getters, and setters
so that chapter name and duration behave as expected
Audiobook
Audiobook class. Your tests should cover all the behavior
described in the specification
Playlist
Playlist class. Your tests should cover all the behavior
described in the specification
maxBST
maxBST method. Test that the proper value is returned in a
variety of cases
Integer Comparators to create these BSTs
maxBinaryTree and isBST
maxBST tests
Implement the methods and classes from the specification.
You are encouraged to complete the Testing Requirements before you begin implementation so you can run your tests as you implement each part.
With testing now being required, feedback from Autolab will be given in several phases.