Prev | Current Page 241 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"

Also add instance variables to the Vehicle class for totalMileage
and totalFuelConsumed. Further, add an accessor method called fuelEconomy that will return
the total miles per gallon of the vehicle.
What will you do to make the refuel method work properly when invoked on an instance of
Skateboard? Write a test class called ManyVehicles that creates a variety of different
Vehicles, exercises all the methods you have created, and checks for proper execution. Try to set the
speed of a Skateboard to 60, for example, or to refuel a Skateboard. Check that the fuel economy
calculations are being performed correctly.
5.10 Write a class that extends Exception and is called TooManyOccupantsException. Have the
Vehicle class mutator for number of occupants throw such an exception if the numberOfOccupants
would exceed the maximum number of occupants for the vehicle. What will you need to change in your
ManyVehicles test class?
5.11 Change your ManyVehicles class so that it reads from a text file called Vehicles.txt the specifications
for the Vehicles to create. Use a BufferedReader or a Scanner to read the file. Using a
Scanner is probably easier in this case. Here is a sample Vehicles.txt file. The first word in a
line is the color, the second word in a line is the make, the third word is the model, and the fourth word
is the maximum number of occupants:
red Ford F-150 3
silver BMW 328i 4
blue GM bus 32
gold Chrysler PTCruiser 4
orange WorldIndustries ProBoard 1
5.


Pages:
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
stretching exercises grow taller akademia pokera noclegi swinoujscie zasady pokera teksty piosenek