Obejec-oriented Design: Car
Design an Class Structure for a Car
1 public class Engine 2 { 3 public string manufacturer; 4 public float displacementSize; 5 public boolean turboCharged; 6 public int cylinders 7 public int mileCount; 8 9 } 10 public class Transmission 11 { 12 public boolean isAutomatic; 13 public int gearCount; 14 } 15 public class Wheel 16 { 17 public int size; 18 public string manufacturer; 19 public string model; 20 } 21 public abstract class Vehicle 22 { 23 public String make; 24 public String model; 25 public int year; 26 public int personCapacity; 27 } 28 29 public abstract class WheelVehicle extends Vehicle //bicycle would extend this 30 { 31 public Wheel[] wheels; 32 } 33 34 public abstract class PropelledWheelVehicle extends WheelVehicle //segway could extend this, as could motorcycle 35 { 36 public Engine e; 37 public Transmission t; 38 39 } 40 //this is likely the class a car would extend. 41 public abstract class PropelledWheelVehicleWithDoors extends PropelledWheelVehicle 42 { 43 public Door[] doors; 44 } 45 public class Car extends PropelledWheelVehicleWithDoors 46 { 47 48 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。