import javax.swing.*;
public class Patron extends Person
{
	private Item[] item;

	public Patron()
	{
	}

	public Patron(int pid, String pname, Item[] item)
	{
		setID(pid);
		setName(pname);
		checkItemOut(item);
	}

	public void setItem(Item[] item)
	{
		this.item = new Item[item.length];
		for (int i = 0; i<item.length; i++)
		{
			this.item[i] = item[i];
		}
	}

	public Item getItem(int i) {return item[i];}

	public void checkItemOut(Item[] item)
	{
		if (item != null)
		{
			if (item.length > 3)
			{
				JOptionPane.showMessageDialog(
 					null, "No more than 3 items please!","Checkout Error",
					JOptionPane.ERROR_MESSAGE);
				this.item = new Item [3];

			}
			else
			{
				this.item = new Item [item.length];
			}

			this.item = item;
			for ( int i = 0; i < this.item.length; i++)
			{
				item[i].checkOut();
			}
		}
	}

	public void checkItemIn(String title)
	{
		for ( int i = 0; i < this.item.length; i++)
		{
			if ( item[i].getTitle().equals(title))
			{
				item[i].checkIn();
				this.item[i] = null;
			}
		}
	}


	public String printPatron()			//public String toString()
	{
		String output = "";
		output+=getID()+", ";
		output+=getName()+": ";
		output+=item.length + " item(s)\n";

		for (int i = 0; i< item.length; i++)
		{
			if (item[i] == null)
			{
				output+= "no items";
			}
			else
			{
				output+="--"+item[i].getTitle();
			}
			output+="\n";
		}
		return output;

	}
}
