Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Draw the uml diagram of the following codes created for the music player system import java.util.Iterator; import java.util.List; class ConcreteMusicIterator implements Iterator { private List

Draw the uml diagram of the following codes created for the music player system
import java.util.Iterator;
import java.util.List;
class ConcreteMusicIterator implements Iterator {
private List songs;
private int position =0;
public ConcreteMusicIterator(List songs){
this.songs = songs;
}
@Override
public boolean hasNext(){
return position < songs.size();
}
@Override
public Song next(){
if (!hasNext()){
throw new RuntimeException("No more songs available.");
}
Song song = songs.get(position);
position++;
return song;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
class MusicCollection implements Iterable {
private List songs;
public MusicCollection(){
songs = new ArrayList<>();
}
public void addSong(Song song){
songs.add(song);
}
public List getSongs(){
return songs;
}
@Override
public Iterator iterator(){
return songs.iterator();
}
}
import java.util.Iterator;
interface MusicIterator extends Iterator {
boolean hasNext();
Song next();
}
import java.util.Iterator;
public class MusicPlayerApp {
public static void main(String[] args){
MusicCollection musicCollection = new MusicCollection();
musicCollection.addSong(new Song("Shape of You", "Ed Sheeran"));
musicCollection.addSong(new Song("Believer", "Imagine Dragons"));
musicCollection.addSong(new Song("Havana", "Camila Cabello"));
System.out.println("Music Collections:");
Iterator iterator = musicCollection.iterator();
while (iterator.hasNext()){
Song song = iterator.next();
System.out.println(song.getTitle()+"-"+ song.getArtist());
}
}
}
class Song{
private String title;
private String artist;
public Song(String title, String artist){
this.title = title;
this.artist = artist;
}
public String getTitle(){
return title;
}
public String getArtist(){
return artist;
}
}

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

4. Schedule individual conferences with students.

Answered: 1 week ago

Question

What are some sources of ethical guidance?

Answered: 1 week ago