Advertisement
Guest User

Test

a guest
Aug 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.LinkedList;
  3.  
  4. public class Album {
  5.     private String name;
  6.     private String artist;
  7.     private SongList songList;
  8.  
  9.     public Album() {
  10.     }
  11.  
  12.     public Album(String name, String artist) {
  13.         this.name = name;
  14.         this.artist = artist;
  15.         this.songList = new SongList();
  16.     }
  17.  
  18.     public String getName() {
  19.         return name;
  20.     }
  21.  
  22.     public String getArtist() {
  23.         return artist;
  24.     }
  25.  
  26.     private Album.SongList songList1 = new SongList();
  27.  
  28.     public boolean addSongToAlbum(String title, double duration) {
  29.         if (this.songList.findSong(title) == null) {
  30.             this.songList.songs.add(new Song(title, duration));
  31.             System.out.println("Dodales utwor \"" + title + "\" do albumu \"" + this.name + "\".");
  32.             return true;
  33.         }
  34.         System.out.println("Utwor \"" + title + "\" juz istnieje w albumie \"" + this.name + "\".");
  35.         return false;
  36.     }
  37.  
  38.  
  39.     public boolean addToPlaylist(int trackNumber, LinkedList<Song> playlist) {
  40.         int index = trackNumber;
  41.         if(index > 0 && index < this.songList1.songs.size()){
  42.             playlist.add(this.songList1.songs.get(index));
  43.             System.out.println("Dodano utwor o numerze \"" + trackNumber + "\" do playlisty. " + this.songList.songs.get(index).toString()+"s.");
  44.             return true;
  45.         }
  46.         System.out.println("Ten album nie ma utworu o indexie " + trackNumber);
  47.         return false;
  48.     }
  49.  
  50.     public boolean addToPlaylist(String title, LinkedList<Song> playlist) {
  51.         if(this.songList.findSong(title) != null){
  52.             int index = this.songList.songs.indexOf(title);
  53.             playlist.add(this.songList.findSong(title));
  54.             System.out.println("Dodano utwor o tytule \"" + title + "\" do playlisty");
  55.             return true;
  56.         }
  57.         System.out.println("Nie znaleziono utworu o tytule \"" + title + "\" ");
  58.         return false;
  59.     }
  60.  
  61.     public static class SongList{
  62.         private ArrayList<Song> songs = new ArrayList<Song>();
  63.  
  64.         public SongList() {
  65.             this.songs = new ArrayList<Song>();
  66.         }
  67.  
  68.         public Song findSong(String title) {
  69.             Song isSong;
  70.             for (Song x : SongList.this.songs) {
  71.                 if(x.getTitle().equals(title)){
  72.                     isSong = x;
  73.                     return isSong;
  74.                 }
  75.             }
  76.             return null;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement