Question: Java Practice Exercise Write a class called Book in java that has the following instance variables: String title, int pages with the required accessor and
Practice Exercise Write a class called Book in java that has the following instance variables: String title, int pages with the required accessor and toString () methods. Now write a subclass "Textbook" of this class "Book" that has the following additional instance variable: String course. Override the toString 0 method of the "Book" class by printing the type of the book (TextBook), the title of the book, the number of pages and the course. Use another accessor method getCourse(). Now in a main class, create an array of 10 books with some of them being textbooks. Using a for-loop print their titles, number of pages and if it is a textbook, then its course. Finally, count the number of textbooks, the number of books and print their quantities. SAMPLE OUTPUT: The following is a sample output >> Book: ABC, \# Pages =100 Book: Arabic, \# Pages =100 Text Book: Data Structures, ICS-202, \# Pages = 200, Course = ICS-202 Text Book: Writing Practice, ENGL-101, \# Pages = 300 , Course = ENGL-101 Text Book: Algebra, MATH-101, \# Pages =500, Course = MATH-101 Book: Water Conservation, \# Pages =200 Book: Environment, \# Pages =150 Book: Teach yourself Visual C++, \#Pages =300 Book: Notebook, \# Pages =300 Text Book: Introduction to Technology, TECH-102, \# Pages =500, Course = TECH-102 Number of Books =6 Number of TextBooks =4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
