import javax.swing.*;
public class Library1		//************ No CDs in this Library1
{
	//Declare object arrays; they have class scope
	ID[] id = new ID[50];
	Item[] item = new Item[30];
	Book[] book = new Book[3];
	Person[] person = new Person[10];
	Patron[] patron = new Patron[3];
	Artist[] artist = new Artist[3];	//assume only 1 artist in each CD
	Author[] author;					//could be 2 or more authors in each book


	public static void main (String[] args)						// MAIN
	{
		Library1 lib = new Library1();

		lib.addBookAuthor();
		lib.addPatron();
		lib.showBookAuthor();
		lib.showPatron();
		//lib.showBookAuthor();
		//lib.patron[0].checkBookIn();
		//lib.patron[2].checkBookIn();
		//lib.showPatron();
		//lib.showBookAuthor();
		System.exit(0);
	}

	private void addBookAuthor()
	{
		author = new Author[1];
		author[0] = new Author (001, "Harper Lee", "5/23/54");
		book[0] = new Book (101, "To kill a Mockingbird", author , 2, true);

		author = new Author[2];	//---- 2 authors in this book
		author[0] = new Author (002, "Amy Tan", "1/03/14");
		author[1] = new Author (003, "Jack London", "1/12/06");
		book[1] = new Book (102, "The Joy Luck Club", author, 1, true);

		author = new Author[1];
		author[0] = new Author (004, "C.S.Lewis", "2/03/74");
		book[2] = new Book (103, "Perelandra", author, 2, true);
	}

	private void addPatron()
	{
		patron[0] = new Patron(1, "Fred Capestany", 0, book[2]);
		patron[1] = new Patron(2, "Gurpreet Kaur", 0, null);
		patron[2] = new Patron(3, "Vera Doroshenko", 0, book[2]);
	}

	private void showBookAuthor()				//Books Library Inventory
	{
		String output = "";
		for (int i=0; i<book.length; i++)
		{
		output+=book[i].getID()+", ";
		output+=book[i].getTitle()+", ";
		output+=book[i].getNum_copies()+", ";
		output+=book[i].getCheckStatus()+", ";

			//------------------------------number of authors in each book

			int numAuthors;
			if ( book[i].getAuthor() == null)
			{
				numAuthors = 0;
			}
			else
			{
				numAuthors = book[i].getAuthor().length;
				for (int x=0; x<book[i].getAuthor().length; x++)
				{
					output+=book[i].getAuthor()[x].getName();

					if(numAuthors >1)		//if 2 or more authors in the book
					{
						output+=", ";		//put comma between authors
						numAuthors--;
					}
				}
			}
			output+="\n";
		}
		output+="\n\nThere are " +book.length+ " books in inventory.";
		JOptionPane.showMessageDialog(null, output,"Books Library Inventory",
									JOptionPane.PLAIN_MESSAGE);
	}


	private void showPatron()
	{
		String output = "";
		for (int i=0; i<patron.length; i++)
		{
			output+=patron[i].getID()+", ";
			output+=patron[i].getName()+", ";

			if (patron[i].getBook() == null)
			{
				output+= "no books";
			}
			else
			{
				output+=patron[i].getBook().getTitle();
			}
			output+="\n";
		}


		output+="\n\nThere are " + patron.length + " library patrons.";
		JOptionPane.showMessageDialog(null, output,"Patron Summary",
										JOptionPane.PLAIN_MESSAGE);
	}
}

