Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Programming

ATE16
ATE16 


Picky Publishing House publishes stories in three categories and has strict require ments for page counts in each category. Create an abstract class named Story that includes a story title, an author name, a number of pages, and a String message. Include get and set methods for each field. The method that sets the number of pages is abstract. Also include constants for the page limits in each category. Create three Story subclasses named Novel, Novella, and ShortStory, each with a unique setPages() method. A Novel must have more than 100 pages, a Novella must have between 50 and 100 pages inclusive, and a ShortStory must have fewer than 50 pages. If the parameter passed to any of the set methods in the child class is out of range, set the page value but also create and store a message that indicates how many pages must be added or cut to satisfy the rules for the story type. Write an application named StoryDemo that creates an array of at least six objects to demonstrate how the methods work for objects created both with valid and invalid page counts for each story type. For each story, display the title, author, page count, and message if any was generated. Save the files as Story.java, Novel.java, Novella.java, ShortStory.java, and StoryDemo.java I HAVE ATTACHED CODE FOR ABOVE PROGRAMS. I NEED HELP WITH MAKEING THE FOLLOWING PROGRAM WITH INSTRUCTIONS BELOW. Write an exception program to display the invalid page count message and save it as InvalidPageCountException. Java. Adapt the previous programs to use the Exception program. Attachments Tags Clarifications

Answers

Program

sudheer488
sudheer488 



Program is done as per requirements and output screenshots were pasted Attachments
InvalidPageCountException.java (1 K) Download Preview
exception details public InvalidPageCountException(String str1) { super(str1); } /* public String toString()

Novel.java (1 K) Download Preview
if(pages < super.MIN_PAGES_IN_NOVEL) { super.setMessage("You still need "+(super.MIN_PAGES_IN_NOVEL - pages)+" pages."); throw new InvalidPageCountException("Invalid Page numbers were mentioned in the Novel"); }

Novella.java (1 K) Download Preview
extends Story { public Novella(String title,String authorName,int pages)throws InvalidPageCountException { super(title,authorName); setPages(pages); } public void setPages(int pages)throws InvalidPageCountException { super.numberOfPages = pages; if(pages < super.MIN_PAGES_IN_NOVELLA)

outputs1.PNG (10 K) Download Preview

Outputs2 when invalid page numbers mentioned.PNG (6 K) Download Preview

ShortStory.java (1 K) Download Preview
ShortStory(String title,String authorName,int pages)throws InvalidPageCountException { super(title,authorName); setPages(pages); } public void setPages(int pages)throws InvalidPageCountException { super.numberOfPages = pages; if(pages >

Story.java (1 K) Download Preview
this.title = title; this.authorName = authorName; } public String getTitle() { return title; } public String getAuthorName() { return authorName; } public int getNumberOfPages() { return numberOfPages; } public String getMessage()

StoryDemo.java (1 K) Download Preview
{ Story books[] = new Story[6]; books[0] = new Novel("Moby-Dick","Herman Melville",102); books[1] = new Novel("The Great Gatsby","F. Scott Fitzgerald",180); books[2] = new Novella("Breakfast at

Screenshots
Screenshot
Screenshot
Purchase Answer