Advertisement
alexarcan

CARS

Sep 29th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1.  
  2. public abstract class Cars {
  3. private String brand;
  4. private int nbSeats;
  5. private int nbDoors;
  6. private int speed;
  7. private String color;
  8. private Engine engine;
  9.  
  10. public Car(String brand, int nbSeats, int nbDoors, int speed, String color, Engine engine)
  11. {
  12. this.brand = brand;
  13. this.nbSeats = nbSeats;
  14. this.nbDoors = nbDoors;
  15. this.speed = speed;
  16. this.color=color;
  17. this.engine=engine;
  18. }
  19.  
  20. public String toString(){
  21. return this.brand + this.nbSeats+ this.nbDoors +this.speed+ this.engine;
  22. }
  23. }
  24.  
  25. class Engine {
  26. private int power;
  27. private int maxTorque;
  28.  
  29. public Engine(double power, int maxTorque){
  30. this.power=power;
  31. this.maxTorque= maxTorque;
  32.  
  33. }
  34.  
  35. public String toString(){
  36. return " "+ this.power + this.maxTorque;
  37. }
  38. }
  39.  
  40. class PetrolEngine extends Engine{
  41. private boolean hasCat;
  42.  
  43. public PetrolEngine(int maxTorque, int power, boolean hasCat){
  44. super(maxTorque,power);
  45. this.hasCat=hasCat;
  46. }
  47.  
  48. public boolean hasCatalyst(){
  49. return this.hasCat;
  50. }
  51. }
  52.  
  53. class DieselEngine extends Engine{
  54. public String toString(){
  55. return "Diesel engine";
  56. }
  57. }
  58.  
  59. class SUV extends Cars{
  60. private boolean suv4x4;
  61. private boolean gndClearance = true;
  62.  
  63. public boolean is4x4(){
  64. return this.suv4x4;
  65. }
  66.  
  67. }
  68.  
  69. class NormalCars extends Cars{
  70. public String toString(){
  71. return "Normal car";
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement