Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.EmptyStackException;
- import java.util.Stack;
- /**
- *
- */
- /**
- * @author admin
- *
- */
- public final class Table {
- private static final int MAX_COUNT_PAGES=10000;
- Stack<Book> data = new Stack<Book>();
- int totalPages = 0;
- public Table(Stack<Book> data, int totalPages) {
- super();
- this.data = data;
- this.totalPages = totalPages;
- }
- public Table() {
- super();
- this.totalPages = 0;
- }
- public void putBook(Book b){
- if( MAX_COUNT_PAGES > (totalPages+b.getPageCount()) )
- {
- data.push(b);
- totalPages+=b.getPageCount();
- }
- else
- System.out.println("Table is already full of books!");
- }
- public Book popBook() throws EmptyStackException{
- try{
- Book b=data.pop();
- totalPages=totalPages-b.getPageCount();
- return b;
- }
- catch (EmptyStackException exESE){
- System.out.println("Попытка достать из пустого стола");
- throw exESE;
- }
- //return null;
- }
- public String toString(){
- String res = "";
- for(Book elem : data){
- res = res+elem.toString()+'\n';
- }
- return res;
- }
Add Comment
Please, Sign In to add comment