
BO(Question 4.12.1:) Write constructors for the classes SportsShoe and
Runner below, by looking at the MAIN FUNCTION to see how many
arguments each constructor has.

@example
CLASS SportsShoe
BEGIN

PD PROPERTY String model;      COMM(// what kind of shoe it is)
PD PROPERTY double speedBoost; COMM(// the boosting factor of the shoe)

PD COMM(// constructor goes here:)

PD COMM(// Useful method for debugging)
PD POBLIC METHOD String toString()
PD BEGIN
PD PD return "I am a shoe called " + model + " and my boosting factor is " + speedBoost;
PD END
END

CLASS Runner
BEGIN
PD PRIVATE PROPERTY String     name;  COMM(// Runner's name.)
PD PRIVATE PROPERTY int        speed; COMM(// speed of runner in km/hr.)
PD PRIVATE PROPERTY SportsShoe shoes; COMM(// which shoe they are wearing.)

PD COMM(// constructor goes here:)

PD COMM(// Useful method for debugging)
PD POBLIC METHOD String toString()
PD BEGIN
PD PD RETURN "I am a runner and my name is " + name + " and my shoes are " + shoes;
PD END
PD COMM(/**)
PD COMM(*** This private method computeSpeed works out the runners speed,)
PD COMM(*** based on their basic speed and the speed boost due to the)
PD COMM(*** SportsShoe that they are currently wearing.)
PD COMM(*/)

PD COMM(// method goes here:)


PD COMM(/**)
PD COMM(** Prints the result of racing two runners against each other.)
PD COMM(*/)
PD FUNCTION void race(Runner r1, Runner r2)
PD BEGIN
PD PD IF (r1.computeSpeed()>r2.computeSpeed())
PD PD THEN BEGIN
PD PD PD System.out.println("Runner " + r1.name + " beats " + r2.name);
PD PD END
PD PD ELSE BEGIN
PD PD PD System.out.println("Runner " + r2.name + " beats " + r1.name);
PD PD END
PD END
PD COMM(/**)
PD COMM(** Swaps the shoes of two runners.)
PD COMM(*/)
PD FUNCTION void swapShoes(Runner r1, Runner r2)
PD BEGIN
PD PD VAR SportsShoe tempShoe = r1.shoes;
PD PD r1.shoes = r2.shoes;
PD PD r2.shoes = tempShoe;
PD END
END

CLASS RunnerTest
BEGIN
PD BEGINMAIN
PD PD VAR SportsShoe nike    = new SportsShoe("Nike NX-71", 2.0);
PD PD VAR SportsShoe reebock = new SportsShoe("Reebock R20", 2.3);
PD PD VAR SportsShoe puma    = new SportsShoe("Puma P200-MMX",4.8);

PD PD VAR Runner sg = new Runner("Speedy Gonzalez", 55, nike);
PD PD VAR Runner sw = new Runner("Slick Willy", 49, reebock);
PD PD VAR Runner fa = new Runner("Fat Albert", 15, puma);

PD PD Runner.race(sg,sw);
PD PD COMM(// Runner.race(sg,sw,fa);)
PD PD COMM(// sg.raceAgainst(sw);)
PD ENDMAIN
END
@end example

BO(Question 4.12.2:) In the Runner class, write the PRIVATE METHOD
TT(computeSpeed) that has no arguments and returns a double-precision
floating point value that equals the runner's running speed. Note that
the speed of a runner is determined by multiplying their speed
property with the TT(speedBoost) property of the shoes that they are
wearing. For example, Speedy Gonzalez's running speed = 55 * 2.0 =
110.0.

BO(Question 4.12.3:) Fix the TT(race) METHOD so that it checks for a draw.

BO(Question 4.12.4:) By copying the TT(race) method, write a three-parameter
race method for racing three runners against each other. Two methods
in the same class with the same name is called overloading in
J.T.W. and Java. Add a call to this method from the MAIN FUNCTION.

@cindex Overloading methods
@cindex Methods, overloading

BO(Question 4.12.5:) What is the difference between a METHOD and a
FUNCTION?  Write a one parameter method raceAgainst that behaves
exactly like two-parameter FUNCTION race. There are two ways of doing
this, one is to optionally use the this keyword rather than one of the
parameters r1 or r2. The second way is for race to simply call race
using THIS as one of the arguments to the FUNCTION.

@cindex Converting from functions to methods and vice-versa
@cindex Functions to methods and vice-versa
@cindex Methods to functions and vice-versa

BO(Question 4.12.6:) Is it true that any METHOD can be re-worked into a
FUNCTION and vice versa?

@cindex Swapping the properties of two objects
@cindex Property swapping

BO(Question 4.12.7:) The swapShoes method in the TT(Runner) CLASS swaps the
shoes of two runners. Add some code to the MAIN FUNCTION to swap the
shoes of two runners and verify that the shoes do indeed get swapped.

BO(Question 4.12.8:) Write a method called TT(swapNames) that swaps the
names of two runners. You can put this FUNCTION into any CLASS but it
makes the most sense to put it into the TT(Runner) CLASS since it has
two Runner parameters.

BO(Question 4.12.9:) Write a method TT(swapSpeeds) that swaps the speed
properties of two runners.
