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