Define a superclass named Media containing:
- A protected instance variable named title of type String.
- A protected instance variable named length of type double.
- A full-argument constructor to assign the values of data members.
- A no-argument constructor that calls the full-argument constructor and sends "No Title" & 1.0 as parameters.
- Set and get methods for title and length.
- Override toString() to returns a string representation of the instance variables.
Define a subclass of Media named Video . The class should have the following public methods:
- A private instance variable named quality of type String.
- A full-argument constructor to send title and length to the super constructor and assign the value of quality.
- A one-argument constructor to assign the value of quality.
- Set and get methods for quality.
- Override toString() to returns a string representation of the instance variables (use toString() of superclass).
Define a driver class MediaPlayer that contains main method. Declare objects of type Media and Video using all constructors. Then, print the objects.
public class MediaPlyer
need an explanation for this answer? contact us directly to get an explanation for this answer{
public static void main(String[] args)
{
Media m1=new Media();
Media m2=new Media("film",60.5);
Video v1=new Video("1080px");
Video v2=new Video("film","1080px",80.4);
System.out.println( "m1 : "+m1);
System.out.println("mw : "+ m2);
System.out.println( "v1 : "+v1);
System.out.println("v2 : "+ v2);
}
}
class Media
{
protected String title;
protected double length;
public Media(String Title,double Length)
{
this.title=Title;
this.length=Length;
}
public Media()
{
this("No Title",1.0);
}
public void setTitle(String Title){
this.title=Title;
}
public String getTitle()
{
return this.title;
}
public void setLength(double Length)
{
this.length=length;
}
public double getLength(){
return this.length;
}
public String toString() {
return "Title :"+this.title+" , length :"+this.length;
}
}
class Video extends Media
{
private String quality;
public Video(String Title,String Quality,double length)
{
super(Title,length);
this.quality=Quality;
}
public Video(String Quality)
{
this.quality=Quality;
}
public void setQuality(String Quality)
{
this.quality=Quality;
}
public String getQuality()
{
return this.quality;
}
public String toString() {
return super.toString()+" , Quality :" + this.quality;
}
}