Java programming Implement a mutable data type My Pod Our My
Java programming
Implement a mutable data type My Pod. Our My Pod is so simple so we can only add song and find song. An immutable data type Song is provided. Note that each song has fixed size of 8M. Song(String name, int size) Construct a song with name and its size Int get Size() Return the size of the song String get Name() Return the name of the song Our My Pod has limited capacity of 64M. For instance variables, you should have an array of Songs. The size of the array is determined based on the size of a song and the size of MyPod. M\\ Pod() Construct an empty MyPod boolean findSong(Song s) Return true if the Song s is in MyPod, otherwise return false Boolean add Song(Song s) Return true of the Song s is added to the MyPod, otherwise return false Solution
public class Song { int size; String name; public Song(String name,int size) { this.name=name; this.size=size; } public int getSize() { return size; } public void setSize(int size) { this.size = size; } public String getName() { return name; } public void setName(String name) { this.name = name; } } public class MyPod { public MyPod() { } public boolean findSong(Song s) { if (s == null) { return false; } else return true; } public boolean addSong(Song s) { if (s == null) { return false; } else return true; } } public class Main { public static void main(String[] args) { Song song=new Song(\"Song1\",8); song.setName(\"Song2\"); String s=song.getName();//this is the getter function to get the name of song song.setSize(8);//This is the setter function to set the size of song int songSize=song.getSize();//it store the size of song in local variable songSize of type int MyPod myPod=new MyPod(); boolean addedSong=myPod.addSong(song);//It returns the true if the song has been added to Song class boolean find=myPod.findSong(song);//It returns the true if song has been found System.out.println(\"The Song Name is \" +s+\"and song size is \"+songSize); System.out.println(\"Song is found \"+find+ \"and the added song is \"+addedSong); } }