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

Java programming Implement a mutable data type MyPod. Our MyPod is so simple so

ID: 3786325 • Letter: J

Question

Java programming Implement a mutable data type MyPod. Our MyPod 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 getSize() Return the size of the song String getName() Return the name of the song Our MyPod 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. MyPod() Construct an empty MyPod boolean findSong(Song s) Return true if the Song s is in MyPod, otherwise return false boolean addSong(Song s) Return true of the Song s is added to the MyPod, otherwise return false $ Java My Pod MyPod is ready.

Explanation / Answer


public class Song {
   String name;
   int size;
   Song(){
      
   }
   Song(String name,int size){
       setname(name);
       setsize(size);
   }
   public void setname(String name){
       this.name=name;
      
   }
   public void setsize(int size){
       this.size=size;
      
   }
   public String getname(){
       return name;
   }
   public int getsize(){
       return size;
   }
}

mypod.java

import java.util.*;
public class mypod {
   int count=0;
   List<String>mylist=new ArrayList<String>();
   int capacity=64;
   mypod(){
      
   }
  
public   boolean addsong(Song s){
       String name=s.name;
       boolean flag=false;
       if(count>=4) {
           System.out.println("mypod full");
           return false;
       }else{
       if(mylist.contains(name)){
           flag=false;
           System.out.println("song aready in mypod:");
       }else{
           mylist.add(name);
           count++;
          
           flag=true;
           System.out.println("song addes sttus is:");
       }
       }
       return flag;  
   }
public boolean findsong(Song s){
   if(mylist.contains(s.name)){
       return true;
   }else
       return false;
      
}
public void display(){
   System.out.println(mylist);
}
}


mypodsongmain.java:
public class mypodmain {
   public static void main(String[] args) {
       Song s=new Song("swarup",16);
       Song s1=new Song("bangaru",16);
       Song s2=new Song("sasha",16);
       Song s3=new Song("john",16);
       Song s4=new Song("sss",16);
       mypod m=new mypod();
       System.out.println(m.addsong(s));
       System.out.println(m.addsong(s1));
       System.out.println(m.addsong(s2));
       System.out.println(m.addsong(s3));
      
       m.display();
       System.out.println(m.addsong(s4));
       m.display();
       System.out.println("doees song contains in mypod:"+m.findsong(s4));
      
   }
}

output:



song addes sttus is:
true
song addes sttus is:
true
song addes sttus is:
true
song addes sttus is:
true
[swarup, bangaru, sasha, john]
mypod full
false
[swarup, bangaru, sasha, john]
doees song contains in mypod:false

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote