/* * This is a really trivial example of class than can be organized * using the LinkedList. You should not use this. Instead, * you should implement your own -- something that is interesting * to you -- a databse of receipes, baseball players, cars, inventory * record, &c. */ class Food implements Comparable { private String name; // This is the primary key: compareTo looks at it private String color; // This is just an attribute. It doesn't affect order /* * It is perfectly legal to have secondary and tertiary keys, such * as last name, then firstname, then middle initial. If you want to * do this, then the compareTo() method needs to handle them appropriately. */ /* * This should print out your whole record in a nice, readable way */ public String toString() { return name + ": " + color; } /* * You might want to have one or more constructors for your * class -- usual reasons */ public Food (String name, String color) { this.name = name; this.color = color; } /* * This is enables the database to keep things in order * it actually does the comparison... */ public int compareTo (Object f) { return name.compareTo(((Food)f).name); } /* * It is alwasy nice to include a .equals() method, everyone * will assume there is one - even if it is Comparable */ public boolean equals(Object f) { return name.equals(((Food)f).name); } /* * This is just an example of a mutator method for the database * record -- it changes the color of the food. */ public void changeColor(String newColor) { color=newColor; } }