design a class MP3 that has instance variables artist, title, and length in seco
ID: 3570716 • Letter: D
Question
design a class MP3 that has instance variables artist, title, and length in seconds (integer),and a static class variable mp3count. The classhas one constructor that takes three arguments. The constructor must count each mp3. be sure to code get/set methods for each instance variables, and a tostring method. The tostring method returns the information about the mp3 as a string. Be sure to validate the length (on negative or zero length-use default bvalue 1) There should also be a static method getmp3count.
Explanation / Answer
public class MP3{
String artist, title;
int length,cpunt=0;
public void MP3(String title,String artist,int length){
this.title=title;
this.artist=artist;
if(length<1){
this.length=1;
}
else{
this.length=length;
}
count=count+1;
}
public String toString(){//overriding the toString() method
return title+" "+artist+" "+length;
}
public static void main(String args[]){
MP3 obj1=new MP3("abc","star",120);
System.out.println(obj1);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.