import java.util.Scanner;
public class TestGroceryList
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the maximum number of items " +
"grocery list can hold: " );
int n = keyboard.nextInt();
keyboard.nextLine(); // clears buffer
GroceryList shoppingList = new GroceryList(n);
System.out.print("Enter grocery items, one item per line. ");
System.out.println("Enter 'quit' to quit");
String item = keyboard.nextLine();
while ( item.compareTo("quit") != 0)
{
try
{
shoppingList.add(item);
}
catch( ListFullException e)
{
System.out.println( e);
}
item = keyboard.nextLine();
}
System.out.println("My Shopping List \n" + shoppingList);
}
}
/*---------Sample Run --------------jGRASP exec: java TestGroceryList
Enter the maximum number of items grocery list can hold: 4
Enter grocery items, one item per line. Enter 'quit' to quit
apples
oranges
cereal
bread
milk
ListFullException: List is full. Cannot add milk
tea
ListFullException: List is full. Cannot add tea
quit
My Shopping List
apples
oranges
cereal
bread
*/