package LinzaiPractice;



public class BookShelvestest {
	public static void main(String[] args) {
		BookShelves bookShelves =  new BookShelves(100);
		try {
			bookShelves.addbook(new Book("linzai"));
			bookShelves.addbook(new Book("linzai"));
			bookShelves.addbook(new Book("linzai"));
			bookShelves.addbook(new Book("linzai"));
			bookShelves.addbook(new Book("linzai"));
			bookShelves.addbook(new Book("linzai"));
			bookShelves.addbook(new Book("linzai"));
		} catch (OutOfBoundsException e) {
			
		System.out.println(e.getMessage());
		}

		
		bookShelves.showcount();
	}
}


class Book {
	private String name;
	
	
	Book(String name ){
		this.name = name; 
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
}


class BookShelves{
	
	private int  max;
	private static int count = 0;
	private Book[] booklist  ;
	
	public BookShelves(int max) {
		this.max =max;
		booklist  = new Book[max];
	}
	
	public void addbook(Book book) throws OutOfBoundsException{
		
		if(count<max){
			booklist[ count]= book;
			count++;
		}else {
			throw new OutOfBoundsException();
		}
			
		
		
	}
	
	public void showcount(){
		System.out.println(booklist[2].getName()+this.count);
	}
}


@SuppressWarnings("serial")
class OutOfBoundsException extends Exception{
	public OutOfBoundsException() {
	
	}
	
	@Override
	public String getMessage() {
		
		return "ÊéÌ«¶àÁË";
	}
	
}
