/* An application using a generic List of objects. In this case we have a List of ToDo items. */ import java.lancs.*; public class Test { public static ToDo readToDo() throws Exception { BasicIo.prompt("Priority: "); int p = BasicIo.readInteger(); BasicIo.prompt("Description: "); String s = BasicIo.readString(); return new ToDo(p,s); }/* Read in data and create a ToDo object. */ public static void main(String[] args) throws Exception { List l1 = new List(); String prompt = "Type in command: "; String commands = "(end, show, cons, length, add, " + "head, tail, " + "insert, delete, present, reverse, help) "; BasicIo.prompt(prompt + commands); String command = BasicIo.readString(); while (!command.equals("end")) { if (command.equals("show")) System.out.println(l1); if (command.equals("head")) System.out.println(l1.head()); if (command.equals("tail")){ l1 = l1.tail(); 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("Priority: "); int p = BasicIo.readInteger(); BasicIo.prompt("Description: "); String s = BasicIo.readString(); ToDo item = new ToDo(p,s); l1 = l1.add(item); System.out.println(l1); } if (command.equals("insert")){ ToDo item = readToDo(); l1 = l1.insert(item,new ToDoComp()); System.out.println(l1); } if (command.equals("present")) { BasicIo.prompt("Id No: "); int e = BasicIo.readInteger(); ToDoPred pred = new ToDoPred(e); System.out.println(l1.isPresent(pred)); } if (command.equals("delete")){ BasicIo.prompt("Id No: "); int e = BasicIo.readInteger(); ToDoPred pred = new ToDoPred(e); l1 = l1.delete(pred); System.out.println(l1); } if (command.equals("reverse")){ l1 = l1.reverse(); System.out.println(l1);} if (command.equals("help")) System.out.println(commands); BasicIo.prompt(prompt); command = BasicIo.readString(); } } }