import javax.swing.*;
public class Book
{
	private int bid;
	private String title;
	private Author[] authors;
	private int copy;
	private boolean haveCopy;

	public Book()
	{
	}

	public Book(int bid, String title, Author[] authors, int copy)
	{
		setBook_id(bid);
		setTitle(title);
		setAuthors(authors);
		setNum_copies(copy);
		if (copy < 1)
		copy = 1;
		haveCopy = true;

	}

	//----------change data
	public void setBook_id(int bid) 		{this.bid = bid;}
	public void setTitle  (String title) 	{this.title = title;}
	public void setAuthors(Author[] authors){this.authors = authors;}
	public void setNum_copies(int copy) 	{this.copy = copy;}

	public void checkIn()
	{
		haveCopy = true;
		copy++;
	}

	public void checkOut()
	{
		if (haveCopy == false)
		{
			JOptionPane.showMessageDialog(
			null,"There is no copy in stock", "error", JOptionPane.ERROR_MESSAGE);
		}
		else
		{
		setNum_copies(getNum_copies() - 1);
		if (getNum_copies() == 0)
			haveCopy = false;
		}
	}
							//*****need decrement num. of copy

	//----------retrieve data
	public int 		getBook_id() 	{return bid;}
	public String 	getTitle() 		{return title;}
	public Author[] getAuthors() 	{return authors;}
	public int 		getNum_copies() {return copy;}
	public String 	getCheckStatus()
	{
		if(haveCopy == true)
		{
			return "Book is on shelf";
		}
		return "Book is checked out";
	}

	//------------------
	public Author getAuthor(String aname)
	{
		for (int i=0; i<authors.length; i++)
		{
			if (authors[i].getAName().equals (aname))
			return authors[i];
		}
		return null;
	}
}