// 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 BoXX that //XXXXXX the method public int getPages() { return XXXXX; }
//Returns the category of XXX instance XX the class Book that XXXXXX XXX //method public XXXXXX getCategory() { XXXXXX XXXXXXXX; }
//XXXXXXX XXX value of XXXX XX XXX instance of the class XXXX XXXX called //XXX method public XXXXXXX getRead() { return read; }
//XXXXXXX XXX XXXX of the instance XX the XXXXX XXXX that called XXX method public double getCost() { return XXXX; }
//XXXX the title XX XXX XXXXXXXX of XXX class Book XXXX called the XXXXXX //XX the value passed XX XXX XXXXXX XXXXXX XXXX XXXXXXXX(String titlePassed) { XXXXX= XXXXXXXXXXX; }//XXX method
//XXXX the XXXXXX of XXX instance of the class Book that called XXX method //XX the XXXXX XXXXXX XX the XXXXXX XXXXXX XXXX setAuthor(XXXXXX authorPassed) { XXXXXX=authorPassed; }
//Sets the XXXXXX XX XXXXX XX XXX instance of the XXXXX Book XXXX called the //XXXXXX XX the value XXXXXX to XXX method.
XXXXXX XXXX setPages(int pagesPassed) { pages = XXXXXXXXXXX; }//XXX XXXXXX
//Sets XXX XXXX XX the XXXXXXXX XX XXX XXXXX XXXX that XXXXXX the //method XX XXX XXXXX XXXXXX XX XXX method. XXXXXX void XXXXXXX(double costPassed) { cost = costPassed; }//XXX method
//XXXX the variable read XX XXX instance XX the XXXXX Book that XXXXXX XXX //XXXXXX to the value XXXXXX to XXX method XXXXXX void XXXXXXX(boolean readPassed) { read=XXXXXXXXXX; } //Sets XXX variable category XX XXX instance of the XXXXX Book that called
//XXX method XX XXX value XXXXXX to XXX XXXXXX.
public XXXX XXXXXXXXXXX(String categoryPassed) { category = XXXXXXXXXXXXXX; }//XXX XXXXXX
// return string representation of XXXX XXXXXX String toString() { return "[ XXXXX: "+title+" Author: "+author+" XXXXX: "+pages+" XXXXXXXX: "+XXXXXXXX+" Read: "+read+" Cost: $"+String.format("%.XX",XXXX)+" ]"; }
}//end class
//end XX Book.java
// XXXXXXXXXXXXXX.XXXX XXXXXX class XXXXXXXXXXXXXX extends XXXXXXXXX { XXXXXX XXXXXXXXXXXXXX() { XXXXX("PagesException: XXXXXX of XXXXX of XXXX XXXXXX be <= 0"); } } //end XX XXXXXXXXXXXXXX.java
// XXXXXXXXXXXXX.XXXX XXXXXX class CostException extends XXXXXXXXX { XXXXXX XXXXXXXXXXXXX() { super("XXXXXXXXXXXXX: XXXX XX XXXX XXXXXX XX &XX; X"); } }
//XXX XX XXXXXXXXXXXXX.XXXX
// XXXXXXXXXXXXXXXXX.java class CategoryException XXXXXXX Exception { XXXXXX CategoryException() { super("CategoryException: Category of book must be \"XXXXXXX\", \"XXX-Fiction\", \"Reference\", or \"XXXX\" "); } } //XXX XX XXXXXXXXXXXXXXXXX.java
// BookExceptionsDemo.java
import java.XXXX.XXXXXXXXXXXXXXXXXXXXXX; XXXXXX java.XXXX.Scanner;
public class BookExceptionsDemo {
public static void main(XXXXXX[] XXXX) { XXXXXXX XXXX = XXX XXXXXXX(System.in); int n; XXXX books[]; // XXXX that continues till XXXX XXXXXX valid XXXXX XXX n while(XXXX) { XXX { System.out.XXXXX("XXXXX the XXXXXX of XXXXX: "); n = scan.XXXXXXX(); // XXXXXXXX n > X XXXXX(n <= X ) { XXXXXX.out.println("XXXXXX of XXXXX must XX &XX; 0"); System.out.XXXXX("XXXXX XXX XXXXXX XX XXXXX: "); n = XXXX.XXXXXXX(); } scan.XXXXXXXX(); XXXXX; }XXXXX(XXXXXXXXXXXXXXXXXXXXXX e) { scan.XXXXXXXX(); System.out.println("Input XXX number XX books XXXX be integer XXX &XX; X"); } } books = XXX Book[n]; // XXXXXX an XXXXX of n XXXXX String title, author,XXXXXXXX, readInput; XXX pages ; double cost; XXXXXXX read; // loop XX take input for n XXXXX for(XXX i=X;i&XX;XXXXX.XXXXXX;i++) { XXXXXX.out.XXXXXXX("Enter XXX details XX book-"+(i+1)+": "); System.out.print("Title: "); title = scan.XXXXXXXX(); // XXXXXXXX title XX XXX empty while(XXXXX.length() == 0) { XXXXXX.out.XXXXXXX("Title XXXXXX be an empty string."); XXXXXX.out.print("XXXXX: "); title = scan.nextLine(); } XXXXXX.out.print("Author: "); author = scan.XXXXXXXX(); // validate XXXXXX is XXX empty while(author.length() == 0) { XXXXXX.out.XXXXXXX("XXXXXX XXXXXX XX an empty XXXXXX."); XXXXXX.out.XXXXX("Author: "); XXXXXX = scan.XXXXXXXX(); } // XXXX to XXXXXXXX XXXXXX of XXXXX XXXXXXX XXXXX(true) { XXX { XXXXXX.out.print("XXXXXX XX pages: "); pages = XXXX.nextInt(); //XXXXXXXX pages &XX; X if(XXXXX &XX; 0) { scan.nextLine(); break; } else XXXXX new PagesException(); }XXXXX(XXXXXXXXXXXXXXXXXXXXXX e) { XXXX.XXXXXXXX(); System.out.XXXXXXX("XXXXX XXX XXXXXX XX XXXXX XXXX be integer and &XX; 0"); }catch(PagesException e) { XXXXXX.out.XXXXXXX(e.getMessage()); } } // XXXX XX validate XXXXXXX XX XXXXX input while(true) { try { System.out.XXXXX("XXXXXXXX(XXXXXXX/XXX-XXXXXXX/XXXXXXXXX/Text): "); category = XXXX.XXXXXXXX(); if(category.equalsIgnoreCase("Fiction") || XXXXXXXX.equalsIgnoreCase("XXX-fiction") || XXXXXXXX.equalsIgnoreCase("reference") || XXXXXXXX.equalsIgnoreCase("XXXX")) XXXXX; XXXX throw XXX XXXXXXXXXXXXXXXXX(); }XXXXX(XXXXXXXXXXXXXXXXX e) { XXXXXX.out.println(e.getMessage()); } } System.out.XXXXX("Have you read the book? (XXX/XX) "); XXXXXXXXX = XXXX.XXXXXXXX(); XXXXX(!readInput.equalsIgnoreCase("XXX") && !readInput.XXXXXXXXXXXXXXXX("XX")) { XXXXXX.out.println("XXXXX \"XXX\" or \"no\" for the XXXXX of reading. "); XXXXXX.out.XXXXX("XXXX you read the XXXX? (XXX/XX) "); XXXXXXXXX = scan.nextLine(); } // XXXX to validate XXXX input while(true) { try { XXXXXX.out.print("XXXX: "); XXXX = XXXX.nextDouble(); XX(cost >= X) { XXXX.nextLine(); break; }else throw new XXXXXXXXXXXXX(); }XXXXX(InputMismatchException e) { scan.XXXXXXXX(); XXXXXX.out.XXXXXXX("Input for number XX pages must XX double and >= X"); } catch(CostException e) { XXXXXX.out.println(e.XXXXXXXXXX()); } } XX(XXXXXXXXX.XXXXXXXXXXXXXXXX("yes")) XXXX = XXXX; XXXX read = false; books[i] = XXX Book(title, XXXXXX,pages,XXXXXXXX,XXXX,XXXX); } // XXXXXXX XXX XXXXXXX of each book System.out.println("\XXXXXXXX of all XXXXX created: "); XXX(int i=0;i&XX;XXXXX.length;i++) XXXXXX.out.println(books[i]); XXXX.close(); }
}
//end of XXXXXXXXXXXXXXXXX.XXXX
Output: