This is a Java Programming. -> Create a class ReadingMaterial. b) Create a subcl
ID: 3861684 • Letter: T
Question
This is a Java Programming.
-> Create a class ReadingMaterial.
b) Create a subclass of RM called Newspaper - should call superclass constructors.
c) Create a subclass of RM called Manga - should call superclass constructors.
d) Create a subclass of RM called Book - should call superclass constructors.
-> Create a class Book.
a) Create a subclass of Book called Textbook - should call superclass constructors.
b) Create a subclass of Book called Novel - should call superclass constructors.
-> Create a class ReadingFactory. ReadingFactory should create a newspaper, a manga, a textbook and a novel.
a) ReadingFactory should contain a method that demonstrates polymorphism by displaying the object sent to it.
b) ReadingFactory should have an arraylist of all the instantiated objects - sort the collection, and then use the display method.
c) Demonstrate casting an object back to its original data type (e.g. cast a ReadingMaterial back to a Novel.)
8) Be sure all methods and JavaDocs included.
=============================================================================================
ReadingMaterial Should never be instantiated.
- language: String
- publisher: String
+ ReadingMaterial(publisher: String, language: String) Set default for language.
+ getLanguage (void): String
+ setLanguage (String): void Default: English
+ setPublisher (String): void
+ getPublisher (void): String
+ toString(): String
===========================================================================================
Book ReadingMaterial
- name: String title
- author: String
- size: Rectangle
- numPages: int
- ISBN: String
+ Book (name: String, author: String, size: Rectangle, numPages: int, ISBN: String)
+ getName(): String
+ getSize(): Rectangle.
+ getNumPages() : int
+ getAuthor(): String
+ setName(String) : void
+ setSize(Rectangle) : void
+ setNumPages(int) : void
+ setAuthor(String) : void
+ getISBN() : String
+ setISBN(String) : void
+ toString() : String
===============================================================================================
TextBook Book
- subject: String
- course : String
+ TextBook(name:String, author: String, size:Rectangle,
numPages:int, ISBN: String, subject: String, course: String)
+ setSubject(String) : void
+ setCourse(String): void
+ getSubject() : String
+ getCourse() : String
+ toString() : String
==============================================================================================
Novel Book
- genre: String
+ Novel(name:String, author: String, size:Rectangle,
numPages:int, ISBN: String, genre: String)
+ setGenre(String) : void
+ getGenre() : String
+ toString() : String
Explanation / Answer
super( ):-
super() is used to invoke super class constructor from subclass constructors only.
By default compiler will place super() call in all constructors of the subclass. It will place super() call without arguments. So by default zero-param constructor will be executed from the super class.
The class ReadingMaterial:-
{
ReadingMaterial()
{
System.out.println(" ReadingMaterial zero-param ");
}
}
The Creation of a subclass Newspaper from ReadingMaterial with superclass constructors:-
{
ReadingMaterial()
{
System.out.println(" ReadingMaterial zero-param ");
}
}
class Newspaper Extends ReadingMaterial
{
Newspaper()
{
System.out.println(" Newspaper zero-param ");
}
public static void main(String[] args)
{
Newspaper obj = new Newspaper();
}
}
The Creation of a subclass Manga from ReadingMaterial with superclass constructors:-
class ReadingMaterial
{
ReadingMaterial()
{
System.out.println(" ReadingMaterial zero-param ");
}
}
class Manga Extends ReadingMaterial
{
Manga()
{
System.out.println(" Manga zero-param ");
}
public static void main(String[] args)
{
Manga obj = new Manga();
}
}
The Creation of a subclass Book from ReadingMaterial with superclass constructors:-
class ReadingMaterial
{
ReadingMaterial()
{
System.out.println(" ReadingMaterial zero-param ");
}
}
class Book Extends ReadingMaterial
{
Book()
{
System.out.println(" Book zero-param ");
}
public static void main(String[] args)
{
Book obj = new Book();
}
}
The class Book:-
class Book
{
Book()
{
System.out.println(" Book zero-param ");
}
}
The Creation of a subclass Textbook from Book with superclass constructors:-
class Book
{
Book()
{
System.out.println(" Book zero-param ");
}
}
class Textbook Extends Book
{
Textbook()
{
System.out.println(" Textbook zero-param ");
}
public static void main(String[] args)
{
Textbook obj = new Textbook();
}
}
The Creation of a subclass Novel from Book with superclass constructors:-
class Book
{
Book()
{
System.out.println(" Book zero-param ");
}
}
class Novel Extends Book
{
Novel()
{
System.out.println(" Novel zero-param ");
}
public static void main(String[] args)
{
Novel obj = new Novel();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.