title: Song constructor in a java playlist
body: <p>Hi there, I'm new here.</p>
  
  <p>I am currently making a playlist software using Java. I want <code>Song</code> to come from a file and store it in a playlist. Should I put something in my song class to indicate that it should come from a file? What are the things that I am missing? Please answer me.</p>
  
  <pre><code>public class Song {
      private Float playTime;
      private String songName;
      private String artist;
  
      //getters
      public Float getPlayTime() { return playTime; }
      public String getSongName() { return songName; }
      public String getArtist() { return artist; }
  }
  </code></pre>
  
  <p>Below is my Playlist class. (Is not mine, I got it somewhere on the net.)</p>
  
  <pre><code>public class Playlist {
  
      //Instance variable
      private List&lt;Song&gt; songs; //arraylist of songs
      private String playlistName; //Playlist name
  
      public Playlist(String name) { 
          songs = new ArrayList&lt;Song&gt;(); //initalize Arraylist to hold Song type
          playlistName = name;
      }
  
      //Methods:
  
      //Returns the playlist name
      public String playlistName() {
          return playlistName;   
      }
  
      //adds Song s to Playlist
      public boolean addSong(Song s) {
          return songs.add(s); 
      }
  
      //return list. Note return is List&lt;Song&gt;.
      public List&lt;Song&gt; getList() {
          System.out.print(playlistName + ":");
          for (int i = 0; i &lt; songs.size(); i++)
          System.out.print(songs.get(i));
          return songs;
      }
  
      public boolean removeSong(Song s) {
          return songs.remove(s);
      }
  
      public double playlistTime() {
          double sum = 0;
          for (int j = 0; j &lt; songs.size(); j++)
              sum = sum + songs.get(j).getPlayTime();
          return sum;
      }
  
      public boolean isSongInPlaylist(String name) {
          boolean x = false;
          for (int i = 0; i &lt; songs.size(); i++)
          if (songs.get(i).getSongName().equalsIgnoreCase(name))
              x = true;  
          return x;
      }
  
      public void songsByArtist(String name) {
          for (int i = 0; i &lt; songs.size(); i++)
              if( songs.get(i).getArtist().equals(name))
                  System.out.println(songs.get(i).getArtist());
      }
  
      public boolean addSongsFrom(Playlist p) { // enter code here
          boolean x = true;
          for (int i = 0; i &lt; p.getList().size(); i++)
              if (p.getList().get(i).getSongName().equals(songs.get(i).getSongName()))
                  x = x;
              else
                  this.addSong(p.getList().get(i));
          return x;
      }
  
      public int totalSongs() {
          return songs.size();
      }
  
      public String toString() {
          return playlistName;
      }
  }
  </code></pre>