// parameterized constructor public Book(String title, String author, int pages, String category, boolean read, double cost) { this.title = title; this.author = author; this.pages = pages; this.category = category; this.read = read; this.cost = cost; }
//Returns the title of the instance of the class Book that called the method public String getTitle() { return title; }
//Returns the author of the instance of the class Book that called the method public String getAuthor() { return author; } //Returns the number of pages of the instance of the class Book XXXX //XXXXXX the XXXXXX public XXX getPages() { XXXXXX pages; }
//Returns XXX XXXXXXXX XX the XXXXXXXX of the XXXXX Book XXXX called the //method XXXXXX String XXXXXXXXXXX() { XXXXXX category; }
//XXXXXXX XXX value XX XXXX XX the XXXXXXXX XX the class XXXX XXXX XXXXXX //the method XXXXXX XXXXXXX getRead() { return read; }
//Returns the cost XX XXX XXXXXXXX XX the XXXXX Book XXXX XXXXXX the XXXXXX public double XXXXXXX() { return XXXX; }
//XXXX the title of XXX XXXXXXXX XX XXX class XXXX that XXXXXX XXX method //XX XXX value XXXXXX XX XXX XXXXXX public void setTitle(String titlePassed) { XXXXX= titlePassed; }//XXX method
//XXXX XXX author of the XXXXXXXX XX XXX XXXXX XXXX XXXX XXXXXX the method //to XXX XXXXX XXXXXX XX the XXXXXX public void XXXXXXXXX(XXXXXX authorPassed) { author=XXXXXXXXXXXX; }
//XXXX XXX XXXXXX XX pages of the instance of XXX XXXXX XXXX that called XXX //XXXXXX to the XXXXX passed XX the method.
XXXXXX XXXX XXXXXXXX(int pagesPassed) { pages = XXXXXXXXXXX; }//end method
//Sets the XXXX of the instance XX XXX class Book XXXX XXXXXX XXX //XXXXXX XX XXX value passed to the XXXXXX. XXXXXX void XXXXXXX(XXXXXX costPassed) { cost = costPassed; }//XXX XXXXXX
//XXXX XXX variable XXXX XX the XXXXXXXX of the XXXXX Book XXXX called the //method XX XXX value XXXXXX to XXX XXXXXX public void setRead(boolean XXXXXXXXXX) { XXXX=readPassed; } //Sets XXX XXXXXXXX XXXXXXXX XX the instance of the XXXXX Book XXXX called
//XXX XXXXXX to XXX XXXXX passed XX XXX method.
XXXXXX XXXX XXXXXXXXXXX(XXXXXX XXXXXXXXXXXXXX) { XXXXXXXX = categoryPassed; }//XXX method
// XXXXXX XXXXXX representation XX Book public String toString() { return "[ Title: "+XXXXX+" XXXXXX: "+XXXXXX+" XXXXX: "+XXXXX+" Category: "+XXXXXXXX+" Read: "+XXXX+" Cost: $"+String.format("%.XX",XXXX)+" ]"; }
}//XXX class
//XXX of XXXX.XXXX
// PagesException.java public class PagesException extends XXXXXXXXX { XXXXXX XXXXXXXXXXXXXX() { super("PagesException: Number of pages of book XXXXXX XX &XX;= X"); } } //XXX of XXXXXXXXXXXXXX.java
// XXXXXXXXXXXXX.XXXX public class CostException XXXXXXX XXXXXXXXX { XXXXXX XXXXXXXXXXXXX() { XXXXX("CostException: XXXX of XXXX cannot XX &XX; 0"); } }
//end of CostException.java
// CategoryException.java XXXXX CategoryException extends Exception { public XXXXXXXXXXXXXXXXX() { super("XXXXXXXXXXXXXXXXX: Category XX book must be \"XXXXXXX\", \"Non-Fiction\", \"XXXXXXXXX\", or \"Text\" "); } } //XXX of CategoryException.java
// BookExceptionsDemo.java
import XXXX.util.InputMismatchException; import java.util.XXXXXXX;
XXXXXX class XXXXXXXXXXXXXXXXXX {
public XXXXXX XXXX main(String[] XXXX) { Scanner scan = XXX XXXXXXX(System.in); XXX n; Book books[]; // loop that continues XXXX user XXXXXX XXXXX value for n XXXXX(true) { XXX { System.out.print("XXXXX the number of books: "); n = XXXX.XXXXXXX(); // XXXXXXXX n &XX; X XXXXX(n <= X ) { System.out.XXXXXXX("XXXXXX XX XXXXX XXXX be > X"); System.out.print("XXXXX XXX XXXXXX of books: "); n = scan.XXXXXXX(); } XXXX.XXXXXXXX(); break; }XXXXX(InputMismatchException e) { XXXX.XXXXXXXX(); System.out.XXXXXXX("XXXXX XXX number of XXXXX XXXX XX integer XXX > X"); } } books = new XXXX[n]; // XXXXXX an XXXXX XX n books XXXXXX XXXXX, XXXXXX,category, readInput; XXX pages ; XXXXXX cost; boolean XXXX; // loop XX XXXX XXXXX for n books XXX(int i=X;i<books.XXXXXX;i++) { XXXXXX.out.println("XXXXX the details of book-"+(i+X)+": "); XXXXXX.out.XXXXX("XXXXX: "); title = XXXX.nextLine(); // validate XXXXX XX not empty XXXXX(XXXXX.XXXXXX() == 0) { XXXXXX.out.XXXXXXX("Title XXXXXX XX an empty string."); XXXXXX.out.print("Title: "); title = XXXX.XXXXXXXX(); } System.out.XXXXX("Author: "); XXXXXX = scan.nextLine(); // validate author is not empty XXXXX(author.length() == X) { System.out.XXXXXXX("Author cannot XX an empty XXXXXX."); XXXXXX.out.print("XXXXXX: "); XXXXXX = XXXX.nextLine(); } // loop to validate number XX pages XXXXXXX while(XXXX) { XXX { XXXXXX.out.print("Number XX XXXXX: "); XXXXX = XXXX.nextInt(); //XXXXXXXX XXXXX > X XX(XXXXX > 0) { scan.nextLine(); XXXXX; } XXXX throw XXX PagesException(); }XXXXX(InputMismatchException e) { scan.nextLine(); System.out.println("Input for number XX pages must be integer XXX > 0"); }catch(XXXXXXXXXXXXXX e) { System.out.println(e.XXXXXXXXXX()); } } // XXXX to XXXXXXXX XXXXXXX XX valid XXXXX while(XXXX) { XXX { XXXXXX.out.print("XXXXXXXX(Fiction/XXX-XXXXXXX/XXXXXXXXX/Text): "); category = XXXX.XXXXXXXX(); if(XXXXXXXX.XXXXXXXXXXXXXXXX("Fiction") || XXXXXXXX.XXXXXXXXXXXXXXXX("non-fiction") || XXXXXXXX.equalsIgnoreCase("XXXXXXXXX") || category.XXXXXXXXXXXXXXXX("text")) break; XXXX throw new CategoryException(); }XXXXX(XXXXXXXXXXXXXXXXX e) { XXXXXX.out.println(e.XXXXXXXXXX()); } } XXXXXX.out.print("Have you XXXX the XXXX? (XXX/no) "); XXXXXXXXX = scan.nextLine(); XXXXX(!XXXXXXXXX.equalsIgnoreCase("yes") && !readInput.XXXXXXXXXXXXXXXX("no")) { XXXXXX.out.println("XXXXX \"XXX\" or \"no\" XXX XXX XXXXX XX XXXXXXX. "); System.out.XXXXX("XXXX you read XXX XXXX? (yes/no) "); readInput = XXXX.XXXXXXXX(); } // loop to validate cost input XXXXX(true) { try { System.out.XXXXX("Cost: "); XXXX = XXXX.XXXXXXXXXX(); XX(XXXX >= X) { XXXX.XXXXXXXX(); break; }else XXXXX new CostException(); }catch(XXXXXXXXXXXXXXXXXXXXXX e) { XXXX.nextLine(); System.out.println("XXXXX for number XX pages XXXX XX double XXX >= 0"); } XXXXX(CostException e) { XXXXXX.out.XXXXXXX(e.getMessage()); } } if(XXXXXXXXX.XXXXXXXXXXXXXXXX("yes")) XXXX = XXXX; else read = XXXXX; books[i] = XXX Book(title, author,XXXXX,category,XXXX,cost); } // XXXXXXX XXX details XX each book System.out.XXXXXXX("\XXXXXXXX of XXX books created: "); XXX(int i=X;i<XXXXX.length;i++) XXXXXX.out.println(books[i]); scan.close(); }
}
//end XX BookExceptionDemo.java
Output: