Question
Implement these classes and a interface in 3 Java programs: Class 1: Track(String trackName, String[] musicians, int durSecs) - The constructor creates a track object.
Implement these classes and a interface in 3 Java programs: Class 1: Track(String trackName, String[] musicians, int durSecs) - The constructor creates a track object. String gettrackName() - Accessor for the track name String[] getMusicians() - Accessor for the list of musicians int getDurSecs() - Accessor for the duration of the track Class 2: InfTracklist(String trackName) -- Create a track list with the given name String gettrackName() - Return the name of the track list int num() -- Return the number of tracks in the track list Track start() - Return the current track, and then move the current track to the next item in the list (plays current track, then moves to the next track) void add(Track track) - Add a new track to be the next track The track list works with an iterator interface called TrackIterator, so that the user can move forward or backwards through the list without changing the currently playing track. The track list exports these public methods that use an iterator. TrackIterator iterator() - This returns an instance of a TrackIterator starting from the current track. void reset(TrackIterator it) - Set playback to start from the track pointed to by the track iterator void remove(TrackIterator it) - Remove the track pointed to by the iterator. If the current track is pointed to by the iterator, set it to the next track, or null if there are no more tracks. TrackIterator: The TrackIterator interface represents an iterator that allows you to move through the list from the current point. The Zune uses this to allow you to move through tracks forwards and backwards. The iterator's abstract methods are: Track current() -- Get the current track that the iterator is pointing to void next() - Advance the iteration void previous() - Move backwards in the iteration Since the iterator is defined as an interface in TrackIterator.java, you have to provide a concrete implementation of this interface for your iterator. Provide your own concrete class that implements TrackIterator. Create your iterator implementation as a (non-public) class inside InfTracklist.java. Call it anything you want. Stylistically, a lot of people append "Impl" to their classes that implement an interface, so you could call it TrackIteratorImpl, for example. Casting is the process of converting one type to another. In the program, the InfTracklist.remove(TrackIterator it) method takes a TrackIterator as an argument. That's great, except that TrackIterator is an interface. You really need the class that implements the TrackIterator, which is TrackIteratorImpl. However the argument is of type TrackIterator. So how do we change a TrackIterator to a TrackIteratorImpl? Inside the remove function, we can cast it, like this: TrackIteratorImpl itImpl = (TrackIteratorImpl) it Now we have a itImpl variable that we can use.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started