Create a class named Movie that can be used with your video rental business in java

Create a class named Movie that can be used with your video rental business. The Movie class should have ID Number, and movie title with appropriate getter and setter methods. Also create an equal() method that overrides Object ’s equals() method, where two movies are equal if their ID number is identical. Next, create three additional classes named Action, Comedy, and Drama that are derived from Movie. Finally, create an overridden method named calcLateFees that takes as input the number of days a movie is late and returns the late fee for that movie. The default late fee is $2/day. Action movies have a late fee of $3/day, comedies are $2.50/day, and dramas are $2/day. Test your classes from a main method.

Solution code:

import java.sql.SQLOutput;
class Movie {
    int id;    String title;    public Movie(int id, String title) {
        this.id = id;        this.title = title;    }
    public int getId() {
        return id;    }

    public void setId(int id) {
        this.id = id;    }

    public String getTitle() {
        return title;    }

    public void setTitle(String title) {
        this.title = title;    }


public double calsLateFees(double letDay){
        
        return letDay;}
    public boolean equals(int anObject) {
        if (this.id == anObject) {
            return true;        }
        else            return false;    }

}
















class Action extends Movie{

    public Action(int id, String title) {
        super(id, title);    }

    @Override    public double calsLateFees(double letDay) {

        return super.calsLateFees(letDay*3);    }
}
class comedies extends Movie{

    public comedies(int id, String title) {
        super(id, title);    }

    @Override    public double calsLateFees(double letDay) {

        return super.calsLateFees(letDay*2.5);    }
}
class Drama extends Movie{

    public Drama(int id, String title) {
        super(id, title);    }

    @Override    public double calsLateFees(double letDay) {

        return super.calsLateFees(letDay*2);    }
}


public class MainQ2 {

    public  static  void main(String arg[])
    {
        Drama d;        Action a;        comedies c;        d=new Drama(23,"do bol");        a=new Action(23,"Hero");        c=new comedies(34,"do bol");        System.out.println("\nDrama and action are equal"+d.equals(a.id));        System.out.println("\nLate fees for "+a.title+" equal to "+a.calsLateFees(43));        System.out.println("\nLate fees for "+d.title+" equal to "+d.calsLateFees(43));        System.out.println("\nLate fees for "+c.title+" equal to "+c.calsLateFees(43));
    }
}


OUTPUT








Comments

Popular posts from this blog

A publishing company that markets both book and audio-cassette in java. (Solution)

informed Search and Uninformed Search