Details of this Paper





Key in the classes defined in this module of the course;PolyMain;Book;Almanac;Novel.;Once you get each of these classes keyed in, make sure they compile and execute properly.;Then create a third subclass called Phonethat also extends the Book class.;The Phone class should keep track of the number of yellow pages and the number of white pages in each phone book.;Make sure the Phone subclass you create has a print method having the same signature as the print method in the Book class.;The print method from the Phone class should print the title of the book, followed by the number of yellow pages and white pages contained within the phone book.;Thus, the print method should have the following signature;public void print();The Phone class should also have a constructor having the following signature;public Phone(String title, intwhitePages, intyellowPages);This constructor should sum up whitePages + yellowPages to get the total number of pages in the book. Remember the total pages in the book and the title of the book are set in the constructor for the Book class.;Modify the PolyMain class to create at least one of your phone books and store it in the library.;You should now be able to print the library without having to modify the print method defined within the PolyMain class.;public class Book;private String title;privateint pages;public Book(String title, int pages);this.title = new String(title);setPages(pages), };public void setPages(int pages);this.pages = pages, };publicintgetPages() {return pages;public void print();System.out.println(title + " has " + pages + " pages");public class Almanac extends Book;privateint charts;public Almanac(String title, int pages, int charts);super(title, pages);setCharts(charts);publicbooleansetCharts(int charts);if(charts >getPages());System.err.println("Too many charts");return false, };else;this.charts = charts;return true;publicintgetCharts();return charts, };public void print();super.print();System.out.println(" and " + charts + " charts");public class Novel extends Book;privateint chapters;public Novel(String title, int pages, int chapters);super(title, pages);this.chapters = chapters, };public void print();super.print();System.out.println(" and " + chapters + " chapters");public class PolyMain;public static void main(String [] args);Book [ ] library = new Book [5];library[0] = new Novel("Jaws", 300, 15);library[1] = new Almanac("New World ", 100, 50);library[2] = new Novel("Animal Farm", 250, 9);listBooks(library);static void listBooks(Book [] library);for(inti = 0, i


Paper#69995 | Written in 18-Jul-2015

Price : $27