Guest User

Untitled

a guest
Jan 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.util.EmptyStackException;
  2. import java.util.Stack;
  3.  
  4. /**
  5.  *
  6.  */
  7.  
  8. /**
  9.  * @author admin
  10.  *
  11.  */
  12. public final class Table {
  13.    
  14.     private static final int MAX_COUNT_PAGES=10000;
  15.     Stack<Book> data = new Stack<Book>();
  16.     int totalPages = 0;
  17.    
  18.     public Table(Stack<Book> data, int totalPages) {
  19.         super();
  20.         this.data = data;
  21.         this.totalPages = totalPages;
  22.     }
  23.     public Table() {
  24.         super();
  25.         this.totalPages = 0;
  26.     }
  27.    
  28.     public void putBook(Book b){
  29.         if( MAX_COUNT_PAGES > (totalPages+b.getPageCount()) )
  30.         {
  31.             data.push(b);
  32.             totalPages+=b.getPageCount();
  33.         }
  34.         else
  35.             System.out.println("Table is already full of books!");
  36.     }
  37.    
  38.     public Book popBook() throws EmptyStackException{
  39.         try{
  40.                 Book b=data.pop();
  41.                 totalPages=totalPages-b.getPageCount();
  42.                 return b;
  43.             }
  44.             catch (EmptyStackException exESE){
  45.                 System.out.println("Попытка достать из пустого стола");
  46.                 throw exESE;
  47.             }
  48.         //return null;
  49.     }
  50.    
  51.     public String toString(){
  52.         String res = "";
  53.         for(Book elem : data){
  54.                 res = res+elem.toString()+'\n';
  55.             }  
  56.         return res;
  57.     }
Add Comment
Please, Sign In to add comment