Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

draw uml diagram of the code below import java.util.Iterator; public class MusicPlayerApp { public static void main ( String [ ] args ) { MusicCollection

draw uml diagram of the code below
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());
}
}
}
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();
}
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

What are leverage items, and how should they be managed?

Answered: 1 week ago

Question

When should you avoid using exhaust brake select all that apply

Answered: 1 week ago