public class BoxOfCandyRunner {
	
	public static void printBox(BoxOfCandy candyBox)
	{
		for (int i=0; i< candyBox.box.length; i++)
		{
			for (int j=0; j< candyBox.box[0].length; j++)
			{
				if (candyBox.box[i][j] == null)
				System.out.print("[null]"+ " ");
				else
					System.out.print("["+candyBox.box[i][j].getFlavor()+"]"+ " ");
			}
			System.out.println();
		}
	}
	
	public static void testMoveCandyToFirstRow()
	{
		BoxOfCandy candyBox = new BoxOfCandy();
		
		//init the candyBox
		candyBox.box =  new Candy[4][3];
		
		candyBox.box[0][0] = null;
		candyBox.box[0][1] = new Candy("lime");
		candyBox.box[0][2] = null;
		
		candyBox.box[1][0] = null;
		candyBox.box[1][1] = new Candy("orange");
		candyBox.box[1][2] = null;
			
		candyBox.box[2][0] = null;
		candyBox.box[2][1] = null;
		candyBox.box[2][2] = new Candy("cherry");
		
		candyBox.box[3][0] = null;
		candyBox.box[3][1] = new Candy("lemon");
		candyBox.box[3][2] = new Candy("grape");
		
		//test and print 
		System.out.println("Initial contents of the Candy Box are: ");
		printBox(candyBox);
		System.out.println("----------------------------------");
		
		System.out.println("moveCandyToFirstRow(0)returns: " +candyBox.moveCandyToFirstRow(0));
		System.out.println("Contents of the Candy Box after moveCandyToFirstRow(0) are: ");
		printBox(candyBox);
		System.out.println("----------------------------------");
		
		System.out.println("moveCandyToFirstRow(1)returns: " +candyBox.moveCandyToFirstRow(1));
		System.out.println("Contents of the Candy Box after moveCandyToFirstRow(1) are: ");
		printBox(candyBox);
		System.out.println("----------------------------------");
		
		System.out.println("moveCandyToFirstRow(2)returns: " +candyBox.moveCandyToFirstRow(2));
		System.out.println("Contents of the Candy Box after moveCandyToFirstRow(2) are: ");
		printBox(candyBox);
		System.out.println("----------------------------------");
	}
	
	public static void testRemoveNextByFlavor()
	{
		BoxOfCandy candyBox = new BoxOfCandy();
		
		//init the candyBox
		candyBox.box =  new Candy[3][5];
		
		candyBox.box[0][0] = new Candy("lime");
		candyBox.box[0][1] = new Candy("lime");
		candyBox.box[0][2] = null;
		candyBox.box[0][3] = new Candy("lemon");
		candyBox.box[0][4] = null;
		
		candyBox.box[1][0] = new Candy("orange");
		candyBox.box[1][1] = null;
		candyBox.box[1][2] = null;
		candyBox.box[1][3] = new Candy("lime");
		candyBox.box[1][4] = new Candy("lime");
			
		candyBox.box[2][0] = new Candy("cherry");
		candyBox.box[2][1] = null;
		candyBox.box[2][2] = new Candy("lemon");
		candyBox.box[2][3] = null;
		candyBox.box[2][4] = new Candy("orange");
		
		//test and print
		Candy returnCandy = candyBox.removeNextByFlavor("cherry");
		if (returnCandy!= null) System.out.println("Flavor of the returned Candy after removeNextByFlavor(\"cherry\") is called: "+returnCandy.getFlavor());
		else System.out.println("Candy returned after a call to removeNextByFlavor(\"cherry\") is null");
		System.out.println("Contents of the Candy Box after removeNextByFlavor(\"cherry\")");
		printBox(candyBox);
		System.out.println("----------------------------------");
		
		returnCandy = candyBox.removeNextByFlavor("lime");
		if (returnCandy!= null) System.out.println("Flavor of the returned Candy after removeNextByFlavor(\"lime\") is called: "+returnCandy.getFlavor());
		else System.out.println("Candy returned after a call to removeNextByFlavor(\"lime\") is null");
		System.out.println("Contents of the Candy Box after removeNextByFlavor(\"lime\")");
		printBox(candyBox);
		System.out.println("----------------------------------");
		
		returnCandy = candyBox.removeNextByFlavor("grape");
		if (returnCandy!= null) System.out.println("Flavor of the returned Candy after removeNextByFlavor(\"grape\") is called: "+returnCandy.getFlavor());
		else System.out.println("Candy returned after a call to removeNextByFlavor(\"grape\") is null");
		System.out.println("Contents of the Candy Box after removeNextByFlavor(\"grape\")");
		printBox(candyBox);
		System.out.println("----------------------------------");
	}
	
	public static void main(String args[])
	{
		testMoveCandyToFirstRow();
		testRemoveNextByFlavor();
	}
	
}
