Lyutov02

Book

Feb 17th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.  
  2. public class Book {
  3.  
  4.     String title;
  5.     String author;
  6.     int pages;
  7.     int currentPage;
  8.  
  9.     void printInfo() {
  10.         System.out.println("Book title is " + this.title);
  11.         System.out.println("The author is " + this.author);
  12.         System.out.println("Number of pages is " + this.pages);
  13.         System.out.println("The current page is " + this.currentPage);
  14.     }
  15.  
  16.     void skipPages(int plusPages) throws Exception {
  17.         if(this.currentPage + plusPages > this.pages) {
  18.             throw new Exception();
  19.         } else {
  20.             this.currentPage += plusPages;
  21.         }
  22.     }
  23.  
  24.     void nextPage() throws Exception {
  25.         if(this.currentPage + 1 > this.pages) {
  26.             throw new Exception();
  27.         } else {
  28.             this.currentPage += 1;
  29.         }
  30.     }
  31. }
Add Comment
Please, Sign In to add comment