/* T06n01.java -- Demonstration of basic ADT design. * * This file contains: * o The CS227ListInterface definition, with 8 operations. * o The CS227StringList class which implements CS227ListInterface. * However, CS227StringList's methods are only stubs. * o The T06n01 class, with a main method containing sample calls * to CS227StringList methods. * * Things to note: * o Methods that throw exceptions are not usually noted as such in the * interface specification, but you can add "throws..." to * the interface method headers if you want to. * o Stubbing the methods is a great way to test a testing program * (main, in this example), to ensure that message syntax * is legal. If you want to do something in a test * and discover that you can't, that's a good sign that your * class design (and thus your interface design, if the class is * implementing one) needs to be revised. * o Because IndexOutOfBoundsException is a Runtime exception, it * is unchecked, and therefore we need not catch it in our testing * code. */ interface CS227ListInterface { public int append (ElementType item); public int prepend (ElementType item); public int insert (int location, ElementType item); public ElementType delete (int location); public boolean isEmpty (); public boolean isFull (); public int size (); public int capacity (); public String toString (); } class CS227StringList implements CS227ListInterface { public int append (String item) { // STUB return 0; } public int prepend (String item) { // STUB return 0; } public int insert (int location, String item) throws IndexOutOfBoundsException { // STUB return 0; } public String delete (int location) throws IndexOutOfBoundsException { // STUB return ""; } public boolean isEmpty () { // STUB return true; } public boolean isFull () { // STUB return false; } public int size () { // STUB return 0; } public int capacity () { // STUB return 0; } public String toString () { // STUB return ""; } } public class T06n01 { public static void main (String [] args) { CS227ListInterface aList = new CS227StringList(); aList.prepend("Hi"); aList.append("Hello"); aList.insert(0,"Howdy"); String something = aList.delete(0); int somethingElse = aList.size(); somethingElse = aList.capacity(); boolean logical = aList.isEmpty(); logical = aList.isFull(); System.out.println("There's no useful output from this example.\n" + "Check the documentation to learn why."); } }