Source of ListDemo.java


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