/** This class creates objects that are personal planners. */ public class Planner implements Database { /** Default maximum size of planner. */ private static final int MAXSIZE = 1000; /** Collection of things that must be done. */ private Task[] todo; /** Number of actual tasks in the planner. */ private int numtasks; /** Create a Planner with the default Database starting size. */ public Planner() { this.todo = new Task[STARTSIZE]; this.numtasks = 0; } @Override public int size() { return this.numtasks; } /** Add an item to the planner, expanding the planner if not yet at the maximum size. @param o the item to add @return true if added, false otherwise */ public boolean add(Object o) { if (! (o instanceof Task)) { return false; } if (this.numtasks == this.todo.length && this.numtasks < MAXSIZE) { // make bigger int newsize = this.numtasks * 2; if (newsize > MAXSIZE) { newsize = MAXSIZE; } Task[] temp = new Task[newsize]; for (int i = 0; i < this.numtasks; i++) { temp[i] = this.todo[i]; } this.todo = temp; } this.todo[this.numtasks++] = (Task) o; return true; } @Override public void display() { for (int i = 0; i < this.numtasks; i++) { System.out.println(this.todo[i]); } } @Override public Object find(Object o) { boolean found = false; String s; if (! (o instanceof String)) { return null; } else { s = (String) o; } for (int i = 0; i < this.numtasks; i++) { if (this.todo[i].toString().indexOf(s) >= 0) { return this.todo[i]; } } return null; } // method not implemented ------------- /** Delete an object from the Planner, if there. @param o the object to delete @return true if removed, false otherwise */ public boolean delete(Object o) { return false; } }