Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.LinkedList;
- public class Album {
- private String name;
- private String artist;
- private SongList songList;
- public Album() {
- }
- public Album(String name, String artist) {
- this.name = name;
- this.artist = artist;
- this.songList = new SongList();
- }
- public String getName() {
- return name;
- }
- public String getArtist() {
- return artist;
- }
- private Album.SongList songList1 = new SongList();
- public boolean addSongToAlbum(String title, double duration) {
- if (this.songList.findSong(title) == null) {
- this.songList.songs.add(new Song(title, duration));
- System.out.println("Dodales utwor \"" + title + "\" do albumu \"" + this.name + "\".");
- return true;
- }
- System.out.println("Utwor \"" + title + "\" juz istnieje w albumie \"" + this.name + "\".");
- return false;
- }
- public boolean addToPlaylist(int trackNumber, LinkedList<Song> playlist) {
- int index = trackNumber;
- if(index > 0 && index < this.songList1.songs.size()){
- playlist.add(this.songList1.songs.get(index));
- System.out.println("Dodano utwor o numerze \"" + trackNumber + "\" do playlisty. " + this.songList.songs.get(index).toString()+"s.");
- return true;
- }
- System.out.println("Ten album nie ma utworu o indexie " + trackNumber);
- return false;
- }
- public boolean addToPlaylist(String title, LinkedList<Song> playlist) {
- if(this.songList.findSong(title) != null){
- int index = this.songList.songs.indexOf(title);
- playlist.add(this.songList.findSong(title));
- System.out.println("Dodano utwor o tytule \"" + title + "\" do playlisty");
- return true;
- }
- System.out.println("Nie znaleziono utworu o tytule \"" + title + "\" ");
- return false;
- }
- public static class SongList{
- private ArrayList<Song> songs = new ArrayList<Song>();
- public SongList() {
- this.songs = new ArrayList<Song>();
- }
- public Song findSong(String title) {
- Song isSong;
- for (Song x : SongList.this.songs) {
- if(x.getTitle().equals(title)){
- isSong = x;
- return isSong;
- }
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement