Source of ListDemo.java


  1: 
  2: import java.util.Scanner;
  3: 
  4: public class ListDemo
  5: {
  6:         public static final int MAX_SIZE = 3; //Assumed > 0
  7: 
  8:     public static void main(String[] args)
  9:     {
 10:         OneWayNoRepeatsList toDoList =
 11:                             new OneWayNoRepeatsList(MAX_SIZE);
 12:                                                         
 13:         System.out.println("Enter items for the list, when prompted.");
 14:         boolean moreEntries = true;
 15:         String next = null;
 16:         Scanner keyboard = new Scanner(System.in);
 17: 
 18:         while (moreEntries && !toDoList.isFull())
 19:         {
 20:             System.out.println("Enter an item:");
 21:             next = keyboard.nextLine( );
 22:             toDoList.addItem(next);
 23:             if (toDoList.isFull( ))
 24:             {
 25:                 System.out.println("List is now full.");
 26:             }
 27:             else
 28:             {
 29:                 System.out.print("More items for the list? ");
 30:                 String ans = keyboard.nextLine( );
 31:                 if (ans.trim().equalsIgnoreCase("no"))
 32:                     moreEntries = false; //User says no more
 33:             }
 34:         }
 35: 
 36:         System.out.println("The list contains:");
 37:         int position = toDoList.START_POSITION;
 38:         next = toDoList.getEntryAt(position);
 39:         while (next != null) //null indicates end of list
 40:         {
 41:             System.out.println(next);
 42:             position++;
 43:             next = toDoList.getEntryAt(position);
 44:         }
 45:     }
 46: }