Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

draw uml diagram of the code below ( If possible, I want the image structure be vertical as in the example photo. ) import java.util.Iterator;

draw uml diagram of the code below (If possible, I want the image structure be vertical as in the example photo.)
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;
}
}
image text in transcribed

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

1. How effectively has the writer formatted this rsum?

Answered: 1 week ago

Question

Describe the principles of cloud security.

Answered: 1 week ago