Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. public class Album {
  4.     private Song[] album = new Song[3];
  5.     private ArrayList<Song> list = new ArrayList<Song>();
  6.     private int songcount;
  7.     private int albumduration;
  8.     public void addSong(Song song) {
  9.         for (int i = 0; i < album.length; i++) {
  10.             if (album[i] == null) {
  11.                 album[i] = song;
  12.                 songcount++;
  13.                 albumduration += song.getDuration();
  14.                 break;
  15.             }
  16.         }
  17.     }
  18.     public List<Song> getSongs() {
  19.         return list;
  20.     }
  21.     public int getSongCount() {
  22.         return songcount;
  23.     }
  24.     public int getAlbumDuration() {
  25.         return albumduration;
  26.     }
  27.     public void printSongs() {
  28.         for (int i = 0; i <= list.size(); i++)
  29.             System.out.println(i + album[i].toString());
  30.     }
  31.     public static void main(String[] args) {
  32.         Album hits = new Album ();
  33.         Song a = new Song("Eminem", "shots", 127);
  34.         Song b = new Song("Rihanna", "work", -78);
  35.         Song c = new Song("SnoopDogg", "SWEDEN", 420);
  36.         a.addSong();
  37.         b.addSong();
  38.         c.addSong();
  39.         System.out.println(hits.getSongCount());
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement