0% found this document useful (0 votes)
3 views

Lab 7

1. Creating a very simple library management system. 2. Inheritance using a movie management system.

Uploaded by

rayanraza155
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab 7

1. Creating a very simple library management system. 2. Inheritance using a movie management system.

Uploaded by

rayanraza155
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Task # 1:

class Items{

int numItems;

public void displayInfo(){

System.out.println("The library has "+numItems+" Items");

class Books extends Items{

int numBooks;

@Override

public void displayInfo(){

System.out.println("The library has "+numBooks+" Books");

class Dvds extends Items{

int numDvds;

@Override

public void displayInfo(){

System.out.println("The library has "+numDvds+" Dvds");

}
public class Main {

public static void main(String[] args) {

Items items = new Items();

Books books = new Books();

Dvds dvds = new Dvds();

items.numItems = 400;

books.numBooks = 300;

dvds.numDvds = 100;

items.displayInfo();

books.displayInfo();

dvds.displayInfo();

Output:
Task # 2:
class Movie{

private int idNum;

private String title;

private String rating;

public int daysLate;

public Movie(int idNum, String title, String rating, int daysLate){

this.idNum = idNum;

this.title = title;

this.rating = rating;

this.daysLate = daysLate;

public double calcLateFees(){

return daysLate * 2;

public boolean equals(Movie otherMovie){

if(this.idNum == otherMovie.idNum){

return true;

else{

return false;

}
public void displayInfo(){

System.out.println("Title: "+title+"\nID: "+idNum+"\nRating:

"+rating+"\nLate Fees: $"+calcLateFees());

class Action extends Movie{

public Action(int idNum, String title, String rating, int daysLate){

super(idNum, title, rating, daysLate);

@Override

public double calcLateFees(){

return daysLate * 3;

class Comedy extends Movie{

public Comedy(int idNum, String title, String rating, int daysLate){

super(idNum, title, rating, daysLate);

@Override

public double calcLateFees(){

return daysLate * 2.50;

}
class Drama extends Movie{

public Drama(int idNum, String title, String rating, int daysLate){

super(idNum, title, rating, daysLate);

@Override

public double calcLateFees(){

return daysLate * 2;

public class Main {

public static void main(String[] args){

//Constructors

Movie movie = new Movie(1, "Movie Title", "G", 0);

Action action = new Action(2, "Action Movie", "PG-13", 4);

Comedy comedy = new Comedy(3, "Comedy Movie", "G", 1);

Drama drama = new Drama(4, "Drama Movie", "R", 3);

//Movie

movie.displayInfo();

System.out.println("Are books same?: "+movie.equals(action));

//Action

action.displayInfo();

}
Output:

You might also like