// DrJava saved history v2 import java.util.*; Stack s = new Stack(); s.push("foo"); (Entry)s.pop(); Entry e = (Entry) s.pop(); s.push("foo"); Entry e1 = (Entry) s.peek(); e1; e1.getName(); e1 = (Entry) s.peek(); Entry e2; e2 = (Entry) s.peek(); List daniel = new Empty(); List alan = new Empty(); List cathy = new Empty(); List voltaire = new Cons("xyz", alan); List daniel = new Empty(); List cathy = new Empty(); List cathy = new Empty(); List daniel = Empty.ONLY; List cathy = Empty.ONLY; cathy = Empty.ONLY; List alan = Empty.ONLY; cathy == alan; List jeannie = Empty.ONLY; List mary = new Cons("abc", jeannie); mary; mary.toString(); List jeannie = Empty.ONLY; List mary = new Cons("abc", jeannie); List carolyn = new Cons(new Integer(5), mary); List carmar = carolyn.concat(mary); carmar = carolyn.concat(mary); carmar; carmar.getFirst(); ((Cons)carmar).getFirst(); Cons cm2 = (Cons)((Cons)carmar).getRest(); cm2.getFirst(); throw new RuntimeException("This is an exception!"); import java.util.*; throw new NoSuchElementException("There is no last element of an empty list"); import java.util.NoSuchElementException; import java.util.NoSuchElementException; throw new NoSuchElementException("Attempt to take last element of empty list"); throw new NoSuchElementException("Attempt to take last element of empty list"); // Hint on writing last() in OO style: use a helper method called returnArgIfEmpty(Object o); Integer i1 = new Integer(5); Integer i2 = new Integer(12); i1.compareTo(i2); i2.compareTo(i1); i2.compareTo(i2); Object o1 = "A"; Object o2 = "B"; o2.compareTo(o2); ((Comparable)o1).compareTo(o2); Comparable o1c = (Comparable) o1; o1c.compareTo(o2); o1c.compareTo(new Integer(5)); Alan = new Surgeon(); Alan.operate("Zung"); Alan = new Surgeon(); Betty = new SnakeDoctor(); Alan.operate("Dr. J"); Betty.operate("Zung"); List alan = Empty.ONLY; List helen = new Cons(new Integer(5), alan); alan = Empty.ONLY; helen = new Cons(new Integer(5), alan); helen; cathy = new Cons(new Integer(-13), helen); cathy.getFirst().compareTo(new Integer(7)); ((Comparable)cathy.getFirst()).compareTo(new Integer(7)); Comparable f = (Comparable)cathy.getFirst(); f = (Comparable)cathy.getFirst(); f; f.compareTo(new Integer(-20)); // do something like this: if (f.compareTo(new Integer(-20) == 1) return f; else return new Integer(-20);