Solution to the Inheritance Tutorial ------------------------------------ // A task to do. public class Task { // The estimated amount of time needed to complete this task. protected int estimatedTime; // The actual amount of time needed to complete this task. protected int actualTime; // Constructs a new task with estimated time 'e'. public Task(int e) { estimatedTime = e; actualTime = 0; } // Completes this task with actual time 'a'. // Pre: a > 0. public void complete(int a) { actualTime = a; } // Returns true if this task is complete, false otherwise. public boolean isCompleted() { return actualTime > 0; } // Returns a description of this task. public String toString() { return "estimated time: " + estimatedTime + "; " "actual time: " + actualTime + "; " "isCompleted: " + isCompleted(); } } // A task that involves studying. public class StudyTask extends Task { // The subject to be studied. private String subject; // The books to study. private Vector books; // Constructs a new study task with estimated time 'e' // and subject 's'. public StudyTask(int e, String s) { super(e); subject = s; books = new Vector(); } // Completes this task with actual time 'a'. // Pre: a > 0. public void complete(int a) { super.complete(a); // Throw away the books. books.clear(); } // Adds book 'b' to the list of books to study. public void addBook(String b) { books.add(b); } // Returns a description of this task. public String toString() { return super.toString() + "; " "subject: " + subject + "; " "books: " + books; } }