Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEED MAIN CLASS ONLY NEED MAIN CLASS ONLY Write a program that simulates an MP3

ID: 3533347 • Letter: N

Question

NEED MAIN CLASS ONLY

NEED MAIN CLASS ONLY

Write a program that simulates an MP3 player.

Your program should begin by using the Song class already developed in the tutorials. Modify this class to include another attribute, fileSize, that determines how much bytes of storage space the song uses. Add an accessor getFileSize method and modify the constructor of the Song class to properly make use of this new attribute.

Next, you must define a new class, called MP3_Player, that manages a collection of Song objects. Since you don't know how many songs your player has, you should utilize the ArrayList to manage the songs. Additionally, your MP3_Player should have a storage capacity attribute which represents how much memory/storage the player holds. Your MP3_Player class must allow songs to be added, removed, and played. When a song is added, you should check to ensure that there is enough space remaining in the memory/storage of the MP3_Player; if the file size of the to-be-added song exceeds the remaining space of the player, the song should not be added. When a song is played, it should play the song completely by invoking the play() method of the song until it is completed. When a song is removed, it should be taken out of the MP3_Player ArrayList that holds the songs. The MP3_Player should be able to display the list of songs it holds and display how much memory capacity it has and how much memory remains (based upon the songs' file sizes consuming some memory). Your class must conform to the following API:

Once you have defined these classes, write a main program that instantiates an object of the MP3_Player class and makes use of it, adding songs and displaying information concerning the object.

Be sure to comment your program well.

A sample output of a possible solution:

Justice for All added to the MP3 player.
Wish you were here added to the MP3 player.
You Belong With Me added to the MP3 player.
Cannot add 'Sabotage'; not enough free space.
Cannot add 'Come As You Are'; not enough free space.

MP3 player with capacity of 15, 14 used, contains:
'Justice for All' by Metallica lasts for 11.75 and is 5mb large
'Wish you were here' by Pink Floyd lasts for 6.25 and is 6mb large
'You Belong With Me' by Taylor Swift lasts for 4.0 and is 3mb large

Justice for All is playing at position 0.1
Justice for All is playing at position 0.2
Justice for All is playing at position 0.3
Justice for All is playing at position 0.4
... [ REMOVED FOR BREVITY SAKE]
Justice for All is playing at position 11.600008
Justice for All is playing at position 11.700008
Justice for All has finished playing.
You Belong With Me removed from the MP3 player.
Come As You Are added to the MP3 player.

MP3 player with capacity of 15, 13 used, contains:
'Justice for All' by Metallica lasts for 11.75 and is 5mb large
'Wish you were here' by Pink Floyd lasts for 6.25 and is 6mb large
'Come As You Are' by Nirvana lasts for 3.75 and is 2mb large

NEED MAIN CLASS ONLY

NEED MAIN CLASS ONLY

Here is my Song Class:

public class Song {  
    private String title;
    private String artist;
    private float duration;
    private float currentPlayPosition;
    private boolean isPlaying;
    private float fileSize;

    public Song()
    {
        title = "NO TITLE";
        artist = "NO ARTIST";
        duration = 0.0f;
        currentPlayPosition = 0.0f;
        isPlaying = false;
        fileSize = 0.0f;
        System.out.println("Constructor is finished");
    }

   public Song(String t, String a, float d)
    {
        title = t;
        artist = a;
        duration = d;
        currentPlayPosition = 0.0f;
        isPlaying = false;
        fileSize = 0.0f;
        System.out.println("Constructor with parameters is finished");
    }

   public String toString()
    {
        return "'" + title + "' by " + artist + " lasts for "
            + duration;
    }

   public String getTitle()
    {
        return title;
    }

   public String getArtist()
    {
        return artist;
    }

   public float getDuration()
    {
        return duration;
    }

   public boolean getIsPlaying()
    {
        return isPlaying;
    }

   public float getfileSize()
    {
        return fileSize;
    }

   public void setTitle(String newTitle)
    {
        if (newTitle.compareTo("") != 0)
            title = newTitle;
    }

   public void setArtist(String newArtist)
    {
        if (newArtist.compareTo("") != 0)
            artist = newArtist;
    }

   public void setDuration(float newDuration)
    {
        if (newDuration >=0)
            duration = newDuration;
    }

   public void setfileSize(float newSize)
    {
        if(newSize >=0)
        fileSize = newSize;
    }

   public void Play()
    {
        isPlaying = true;
        currentPlayPosition += 0.1f;

   if (currentPlayPosition < duration)
    {
        System.out.println(title + " is playing at position "
            + currentPlayPosition);
    }
    else
    {
        isPlaying = false;
        System.out.println(title + " has finished playing.");
        currentPlayPosition = 0.0f;
    }
}
}

Here is my mp3 class:

public class Mp3_Player
    {   
     /** The list of songs that will be in Mp3 player. */
     ArrayList<Song> list = new ArrayList<Song>();   
     /** The current storage capacity. */
     int storageCapacity = 0;   
     /** The total capacity. */
     int totalCapacity = 0;
    
     /*
      * Returns the contents of object
      */
    
     public String toString()
     {
         String value = "Capacity "+totalCapacity+", "+storageCapacity+"used"+" ";
         value += "List of songs ";
         Iterator<Song> i = list.iterator();
         while(i.hasNext())
         {
             Song s = i.next();
             value += s.getTitle()+" by "+s.getArtist()+" lasts "+s.getLength()+" and is "+s.getFileSize()+" mb large."+" ";
         }
         return value;
     }
   
     /**
      * Free space left.
      *
      * @return the int
      */
     int freeSpace()
     {
         return storageCapacity;
     }
   
     /**
      * Gets the total storage capacity.
      *
      * @return the total storage capacity
      */
     int getStorageCapacity()
     {
         return totalCapacity;
     }
   
     /**
      * Instantiates a new mp3_ player.
      */
     public Mp3_Player()
     {
         this.totalCapacity = this.storageCapacity = 10;
     }
   
     /**
      * Instantiates a new mp3_ player.
      *
      * @param capacity the capacity
      */
     public Mp3_Player(int capacity)
     {
         this.totalCapacity = capacity;
         this.storageCapacity = capacity;
     }
   
     /**
      * Adds the song if file size is less than storage remaining.
      *
      * @param song the song
      */
     public void addSong(Song song)
     {
         if( (storageCapacity - song.fileSize) > 0 )
         {
             list.add(song);
             storageCapacity -= song.fileSize;
             System.out.println(song.title+" added to Mp3 player.");
         }
         else
             System.out.println("Storage capacity limit reached. Song cannot be added");
     }
   
     /**
      * Play song.
      *
      * @param position the position
      */
     public void playSong(int position)
     {
         if(position < list.size()){
             Song s = list.get(position);
             System.out.println("Playing "+s.title+" by "+s.artist);
             for(float i=0.1f;i<s.length;i+=0.1){
                 System.out.println("Playing positioin "+i);
             }
         }
         else
         {
             System.out.println("Position not present in list");
         }
     }
   
   
     /**
      * Removes the song.
      *
      * @param song the song
      */
     public void removeSong(Song song)
     {
         if(list.contains(song))
         {
             storageCapacity -= storageCapacity - song.fileSize;
             list.remove(song);
             System.out.println("Song removed. Remaining capacity "+storageCapacity);
         }
         else
         {
             System.out.println("Song not found error.");
         }
     }
   
}
}

Explanation / Answer

//here you go, but note that there were multiple errors in your other files in terms of method names

http://ideone.com/61BCz3