任选其中一题:
1) 扩展你的租车行程序,类 Vehicle 下派生出另外两个类:Car 和 Bike,分别有以下主要属
性:
class Car:
int seats number of seats
int airbags number of airbags
class Bike:
boolean horn true(false) if it has(not) a horn
Boolean lights true(false) if it has(not) a lights
从键盘输入 car 及 bike 的相关信息,统计两种类型总数并打印出来。如果用数组储存数
据,可以分别放在不同类型 Car, Bike 的数组里。最后产生 UML 类图。
2) 根据以下继承关系扩展你的程序:从 vehicle 派生出 Motorvehicle 和 Bike, Motorvehicle
又派生出 Car 和 Motorcyle,Bike 与 Car 定义如(1),主要属性:
class Motorvehic le:
← int cc: cubic centimeters of the engine (e.g. 597)
← int hp; horsepower (e.g. 67)
←
class Motorcycle:
int engineStrokes: number of strokes of the engine (e.g. 2)
分别输入Car及Motorcycle信息,统计两种类型总数打印出来,最后产生UMl类图。如果
前面Vehicle用menu实现,参考menu如下:
[A]: Add a vehicle
[S]: Show vehicles
[N]: Number of vehicles
[F]: Save vehicles to files
[Q]: Quit
********************************
Your selection: a
如果用户选择 a, 则进入以下菜单:
[C]: Add a car
评论0