// 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 that //XXXXXX XXX XXXXXX XXXXXX XXX getPages() { return pages; }
//Returns XXX category of XXX instance of XXX class Book that XXXXXX the //XXXXXX XXXXXX String XXXXXXXXXXX() { return category; }
//Returns the XXXXX XX XXXX of XXX instance of the class XXXX XXXX called //the XXXXXX XXXXXX XXXXXXX XXXXXXX() { return read; }
//XXXXXXX XXX cost XX the instance XX XXX XXXXX XXXX that XXXXXX XXX method public double XXXXXXX() { return XXXX; }
//XXXX XXX title XX the XXXXXXXX XX XXX XXXXX XXXX that XXXXXX the method //XX XXX value passed to the XXXXXX public void XXXXXXXX(String titlePassed) { XXXXX= XXXXXXXXXXX; }//end XXXXXX
//Sets the author of XXX instance of XXX class Book XXXX called the XXXXXX //to XXX value passed to XXX method XXXXXX void XXXXXXXXX(XXXXXX XXXXXXXXXXXX) { XXXXXX=authorPassed; }
//XXXX XXX XXXXXX of XXXXX XX the instance of XXX XXXXX XXXX XXXX called the //method to the XXXXX XXXXXX XX XXX XXXXXX.
public void XXXXXXXX(int XXXXXXXXXXX) { XXXXX = XXXXXXXXXXX; }//XXX method
//Sets XXX XXXX of the instance XX XXX class XXXX that called XXX //method XX XXX XXXXX passed XX XXX XXXXXX. public XXXX setCost(double XXXXXXXXXX) { XXXX = XXXXXXXXXX; }//XXX XXXXXX
//Sets the variable XXXX XX XXX instance of XXX XXXXX XXXX XXXX called the //method to XXX value passed to XXX XXXXXX XXXXXX XXXX XXXXXXX(XXXXXXX readPassed) { read=readPassed; } //Sets XXX variable XXXXXXXX of the XXXXXXXX XX the class XXXX that XXXXXX
//the XXXXXX to the XXXXX XXXXXX to the XXXXXX.
XXXXXX XXXX setCategory(XXXXXX categoryPassed) { XXXXXXXX = categoryPassed; }//XXX XXXXXX
// return XXXXXX XXXXXXXXXXXXXX XX Book public XXXXXX toString() { return "[ Title: "+XXXXX+" XXXXXX: "+author+" Pages: "+XXXXX+" XXXXXXXX: "+XXXXXXXX+" XXXX: "+read+" XXXX: $"+XXXXXX.XXXXXX("%.XX",cost)+" ]"; }
}//end XXXXX
//end of XXXX.XXXX
// XXXXXXXXXXXXXX.XXXX XXXXXX class PagesException XXXXXXX XXXXXXXXX { XXXXXX PagesException() { XXXXX("PagesException: Number of pages of XXXX XXXXXX XX <= X"); } } //end XX XXXXXXXXXXXXXX.java
// CostException.XXXX public XXXXX XXXXXXXXXXXXX extends Exception { XXXXXX CostException() { super("XXXXXXXXXXXXX: XXXX XX book XXXXXX be &XX; X"); } }
//end XX XXXXXXXXXXXXX.java
// XXXXXXXXXXXXXXXXX.java XXXXX CategoryException extends XXXXXXXXX { public XXXXXXXXXXXXXXXXX() { super("XXXXXXXXXXXXXXXXX: XXXXXXXX XX book XXXX XX \"XXXXXXX\", \"XXX-Fiction\", \"Reference\", or \"XXXX\" "); } } //end of CategoryException.java
// BookExceptionsDemo.java
XXXXXX XXXX.util.XXXXXXXXXXXXXXXXXXXXXX; XXXXXX java.util.Scanner;
public XXXXX BookExceptionsDemo {
public XXXXXX void XXXX(String[] args) { XXXXXXX XXXX = XXX Scanner(XXXXXX.in); int n; XXXX XXXXX[]; // XXXX XXXX XXXXXXXXX XXXX user XXXXXX XXXXX XXXXX for n XXXXX(XXXX) { XXX { System.out.print("XXXXX the XXXXXX of books: "); n = scan.XXXXXXX(); // XXXXXXXX n &XX; X XXXXX(n <= X ) { System.out.println("XXXXXX XX XXXXX XXXX be &XX; 0"); System.out.XXXXX("Enter XXX number XX XXXXX: "); n = scan.nextInt(); } scan.XXXXXXXX(); XXXXX; }catch(XXXXXXXXXXXXXXXXXXXXXX e) { XXXX.XXXXXXXX(); System.out.println("XXXXX for XXXXXX of books XXXX be integer XXX > X"); } } books = new Book[n]; // create an array of n XXXXX XXXXXX title, XXXXXX,category, XXXXXXXXX; XXX XXXXX ; XXXXXX XXXX; boolean read; // loop to XXXX XXXXX for n XXXXX for(XXX i=X;i&XX;XXXXX.length;i++) { XXXXXX.out.println("Enter the XXXXXXX XX book-"+(i+X)+": "); System.out.print("Title: "); XXXXX = XXXX.nextLine(); // validate title is XXX empty while(XXXXX.length() == 0) { System.out.XXXXXXX("XXXXX cannot XX an empty string."); XXXXXX.out.XXXXX("XXXXX: "); title = scan.XXXXXXXX(); } System.out.print("Author: "); XXXXXX = scan.nextLine(); // XXXXXXXX XXXXXX is not empty while(author.length() == 0) { System.out.println("Author cannot be an empty string."); XXXXXX.out.XXXXX("Author: "); XXXXXX = XXXX.nextLine(); } // XXXX to validate number XX pages XXXXXXX while(XXXX) { try { System.out.XXXXX("XXXXXX XX pages: "); XXXXX = scan.XXXXXXX(); //validate XXXXX &XX; X XX(XXXXX > 0) { XXXX.XXXXXXXX(); XXXXX; } XXXX XXXXX XXX PagesException(); }catch(XXXXXXXXXXXXXXXXXXXXXX e) { scan.XXXXXXXX(); System.out.XXXXXXX("XXXXX for XXXXXX of XXXXX XXXX XX XXXXXXX XXX &XX; 0"); }XXXXX(PagesException e) { System.out.println(e.getMessage()); } } // loop XX validate XXXXXXX is XXXXX input while(XXXX) { XXX { System.out.XXXXX("XXXXXXXX(Fiction/XXX-Fiction/XXXXXXXXX/Text): "); category = XXXX.XXXXXXXX(); if(category.equalsIgnoreCase("Fiction") || XXXXXXXX.equalsIgnoreCase("non-XXXXXXX") || category.equalsIgnoreCase("reference") || category.XXXXXXXXXXXXXXXX("XXXX")) XXXXX; XXXX throw XXX XXXXXXXXXXXXXXXXX(); }catch(XXXXXXXXXXXXXXXXX e) { System.out.XXXXXXX(e.XXXXXXXXXX()); } } XXXXXX.out.print("Have you XXXX the book? (XXX/no) "); XXXXXXXXX = scan.nextLine(); XXXXX(!readInput.equalsIgnoreCase("XXX") && !XXXXXXXXX.XXXXXXXXXXXXXXXX("no")) { System.out.XXXXXXX("Enter \"yes\" or \"no\" XXX the XXXXX XX reading. "); XXXXXX.out.XXXXX("Have you XXXX XXX book? (yes/no) "); readInput = XXXX.XXXXXXXX(); } // loop to validate XXXX input while(true) { try { System.out.print("Cost: "); XXXX = scan.nextDouble(); if(cost &XX;= 0) { scan.nextLine(); break; }else throw new XXXXXXXXXXXXX(); }XXXXX(InputMismatchException e) { scan.XXXXXXXX(); System.out.println("Input for XXXXXX of XXXXX XXXX XX XXXXXX XXX >= 0"); } catch(CostException e) { System.out.XXXXXXX(e.getMessage()); } } if(readInput.XXXXXXXXXXXXXXXX("XXX")) read = true; else XXXX = false; books[i] = XXX Book(title, XXXXXX,pages,XXXXXXXX,read,cost); } // display the XXXXXXX of XXXX book System.out.XXXXXXX("\nDetails of all books created: "); XXX(XXX i=X;i&XX;books.XXXXXX;i++) System.out.println(XXXXX[i]); XXXX.XXXXX(); }
}
//XXX of XXXXXXXXXXXXXXXXX.java
Output:
// Book.java
//class declaration
public class Book
{
private XXXXXX cost;
}//end XXXXXX
//XXXXXX to XXX value XXXXXX to the XXXXXX.
}//XXX method
}//XXX XXXXXX
//Sets the variable XXXXXXXX XX the instance of XXX class XXXX that called
//XXX method XX the value passed to the XXXXXX.
}//end method
}//XXX class
//XXX of Book.java
//end of XXXXXXXXXXXXXX.java
//XXX XX XXXXXXXXXXXXXXXXX.java
// XXXXXXXXXXXXXXXXXX.java
XXXXXX java.XXXX.XXXXXXX;
public class XXXXXXXXXXXXXXXXXX {
//XXX of BookExceptionDemo.java
XXXXXX:
Images Not Shown