Prev | Current Page 239 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"


Your program should prompt the user for the number of wheels on the vehicle, and then read the number
into an int variable. If the user says the vehicle has 2 or 3 wheels, the program will report that it is a
CHAP. 5] PROGRAMMING IN JAVA 93
motorcycle, if it has 4 wheels the vehicle will be labeled a ???car or light truck,??? if it has 6, 8, 10, 12, 14,
16, or 18 wheels, it will be categorized as a truck. Any other number of wheels will be reported as an
error. Use a switch statement to compute the decision.
5.6 Write a Java class called Vehicle. The Vehicle class will have instance attributes for color, make,
model, speed, number of occupants, and maximum number of occupants. The Vehicle class will also
have a static variable called vehicleCount that can be used to track the number of vehicles in the
application. The constructor for Vehicle should expect values for make, model, maximum number of
occupants, and color, and it should set the vehicle speed to zero, the number of occupants to 1, and
increment the count of vehicles each time the constructor is called. Each of the instance and static variables
should have an accessor (get) method that will return the appropriate value, and all except the
vehicleCount variable should also have a mutator (set) method so that the value can be modified.


Pages:
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
plecaki kasyno Peg Perego Vela Easy Drive bad credit loans instant decision no brokers Kocham wakacje