/* * cRecorder * --------- * Author: C. Pollett * Date: Jan 20. 1999 * Purpose: This class can be used to store a list of Objects * * */ public class cRecorder { cRecordNode first, last; /* * Constructors: (only one) * * Example use: * a = new cRecorder(); * This list would create an empty cRecorder instance. */ public cRecorder() { first=last=null; } /* * add - adds an item to a cRecorder instance * *Example: * cRecorder a; * a=new cRecorder(); * . * . * . * a.add("hi There"); * This would "hi there" to the end of the current cRecorder *list. */ public void add(Object data){ cRecordNode tmp; tmp = new cRecordNode(data,null); if(isEmpty()) {first=last=tmp;} else { last.setNext(tmp); last=tmp; } } /* * clear() -- clears the cRecorder list * */ public void clear() { first=last=null; } /* * isEmpty -- returns true iff the current cRecorder list is empty * */ public boolean isEmpty() { return (first == null); } /* * toString() - returns a string listing out the objects in * the cRecorder with one object followed by * a carriage return on each line. * */ public String toString() { //insert your code here. } } /* cRecordNode ----------- Purpose: Auxiliary class to cRecorder used to actually story data in a list */ class cRecordNode { private Object d; private cRecordNode n; cRecordNode(Object data, cRecordNode next) { d=data; n=next; } /* * getData() -- This method returns the data * in a cRecordNode */ Object getData(){ return d; } /* * getNext() -- returns the next cRecordNode * of this instance */ cRecordNode getNext(){ return n; } /* * setNext() -- sets the next cRecordNode * of this instance */ void setNext( cRecordNode next){ n=next; } }