/* Processing of a List of integer objects, using class List This shows that we can implement the functionality in our first example, but using only a list of objects. We need to define predicates and comparators to do this */ import java.lancs.*; public class Test { public static void main(String[] args) throws Exception { List l1 = new List(); String prompt = "Type in command: "; String commands = "(end, show, cons, length, add, " + "insert, reverse, present, help) "; BasicIo.prompt(prompt + commands); String command = BasicIo.readString(); while (!command.equals("end")) { if (command.equals("help")) System.out.println(commands); if (command.equals("show")) System.out.println(l1); if (command.equals("cons")) System.out.println(l1.cons()); if (command.equals("length")) System.out.println(l1.length()); if (command.equals("add")){ BasicIo.prompt("data: "); int i = BasicIo.readInteger(); l1 = l1.add(new Integer(i)); System.out.println(l1);} if (command.equals("insert")){ BasicIo.prompt("data: "); int i = BasicIo.readInteger(); l1 = l1.insert(new Integer(i),new IntComp()); System.out.println(l1); } if (command.equals("present")) { BasicIo.prompt("data: "); int i = BasicIo.readInteger(); IntPred pred = new IntPred(i); System.out.println(l1.isPresent(pred)); } if (command.equals("reverse")){ try { l1 = l1.reverse(); System.out.println(l1); } catch (ListException e){System.out.println("Woops");} } BasicIo.prompt(prompt); command = BasicIo.readString(); } } }