1interface PlaylistIterator {
2 public boolean hasNextSong();
3 public Object getNextSong();
4}
5abstract class Song {
6 public abstract void play();
7}
8class SongPlaylist {
9 public SongPlaylist() {
10 private final int count = 3;
11 private Track[] songs = {new Track("Song A"), new Track("Song B"),
12 new Track("Song C")};
13 }
14 private class Track extends Song {
15 private String title;
16 public Track(String title) {
17 this.title = title;
18 }
19 public void play() {
20 System.out.println("Playing: " + title);
21 }
22 }
23 private class PlaylistIter implements PlaylistIterator {
24 private int currentIndex;
25 public PlaylistIter() {
26 // Constructor
27
28 }
29 public boolean hasNextSong() {
30 // Check if there is a next song
31 }
32 public Object getNextSong() {
33 // Return the next song
34 }
35 }
36 public PlaylistIterator getIterator() {
37 return new PlaylistIter();
38 }
39}
40public class PlaylistTest {
41 public static void main(String[] args) {
42 SongPlaylist playlist = new SongPlaylist();
43 PlaylistIterator iter = playlist.getIterator();
44 while (iter.hasnext()){
45 -----------------------; //LINE 1
46 }
47 }
48}