
First,modify the speed monitor package so that ArrivalTimes is now a subtype of Duration, Ada's type that represents elapsed time. The new spec will look like
PACKAGE Speed_Monitor IS TYPE SpeedClasses IS (Class1, Class2, Class3, Class4, Class5); SUBTYPE Speeds IS Natural RANGE 0..130; SUBTYPE ArrivalTimes IS Duration RANGE 1.0..60.0; FUNCTION Classify (Speed: Speeds) RETURN SpeedClasses; -- Pre: Speed is defined -- Post: Returns the class of the given speed PROCEDURE DeliverSpeed (Speed: OUT Speeds; Time: OUT ArrivalTimes); -- Pre: None -- Post: Delivers a random speed in the range 40..80 -- and a random elapsed time END Speed_Monitor;You'll have to modify the procedure DeliverSpeed so that the integer value delivered by the random number generator is converted to the ArrivalTimes subtype.
Second, change your main program so that the time is reported as an actual time of day rather than an elapsed integer value. Declare your elapsed time variable as Ada.Calendar.Time. Note that Ada.Calendar (p.485) provides a "+" operation to add a Duration value to a Time one.
Program 7.3 shows how to display a value of Ada.Calendar.Time. For each arriving car, classify its speed, and display the elapsed time, speed, and speed class, like this:
Time 12:40:17, Speed 57, Class 3
Finally, at the end of the run, display the total number of cars in each speed category.