In: Computer Science
The purpose of this assignment is to have you become familiar with polymorphism and be able to design classes with inheritance
The purpose of this assignment is to have you become familiar with polymorphism and be able to design classes with inheritance. Task The School Library has many items available for its students; some can be checked out and others cannot. Among those that can be checked out are journal (i.e., a literary journal) and digital video disk (i.e., a DVD). These two types have many attributes in common such as title, publisher, and dewey decimal classification. Design a class to represent the library item that would capture the common features among journals and DVDs. Then, design journal and digital video classes that are derived from the library item base class.
The library item class does not need more attributes (you can use the ones provided if you like), but you should add at least 2 methods to the class. The journal and digital video classes should have at least 3 attributes and at least 2 methods.
I need a java code for this.
Program:
//class LibrayItem
class LibrayItem
{
//attributes
String title;
String publisher;
//method to set title
public void setTitle(String title)
{
this.title = title;
}
//method to set publisher
public void setPublisher(String publisher)
{
this.publisher = publisher;
}
}
//class Journal
class Journal extends LibrayItem
{
//attributes
String editor;
String subject;
String id;
//method to set editor
public void setEditor(String editor)
{
this.editor = editor;
}
//method to set subject
public void setSubject(String subject)
{
this.subject = subject;
}
//method to set id
public void setId(String id)
{
this.id = id;
}
}
//class Dvd
class Dvd extends LibrayItem
{
//attributes
int size;
String dvdNumber;
String returnDate;
//method to set size
public void setSize(int size)
{
this.size = size;
}
//method to set dvdNumber
public void setDvdNumber(String dvdNumber)
{
this.dvdNumber = dvdNumber;
}
//method to set returnDate
public void setReturnDate(String returnDate)
{
this.returnDate = returnDate;
}
}
N.B. Whether you face any problem then share with me in the comment section, I'll happy to help you. I expect positive feedback from your end.