/* CSE 142, Autumn 2007, Marty Stepp This class models a Parent driving children to DisneyLand. It is kind of a stupid example, but we're using it to illustrate the following: - Sometimes I will ask you to write a method (e.g. areWeThereYet) without telling you what fields the object will need - A useful trick is to count the number of calls of a given method, so that you can potentially produce a different response to each call */ public class Parent { // counts how many times the kids have asked us "are we there yet?" int timesAsked; // technically this constructor is not necessary public Parent() { timesAsked = 0; } // Simulates the parent's response to the annoying question, "Are we there yet?" // The Parent gets progressively more annoyed until it grounds the child. public String areWeThereYet() { timesAsked++; if (timesAsked <= 2) { return "Just a little farther."; } else if (timesAsked <= 4) { return "NO."; } else if (timesAsked == 5) { return "STOP ASKING ME THAT!"; } else { return "You're grounded."; } } }