Advertisement
Flaron

ProgMasters_CAR

Nov 11th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. public class Car {
  2.  
  3. private Engine engine = new Engine();
  4. private Wheel[] wheel = new Wheel[4];
  5. private Door left = new Door();
  6. private Door right = new Door(); // 2-door
  7.  
  8.  
  9. public Engine getEngine() {
  10.  
  11. return engine;
  12. }
  13.  
  14. public Wheel[] getWheel() {
  15.  
  16. return wheel;
  17. }
  18.  
  19. public Door getLeft() {
  20. return left;
  21. }
  22.  
  23. public Door getRight() {
  24. return right;
  25. }
  26.  
  27. public Car() {
  28. for(int i = 0; i < 4; i++) {
  29. wheel[i] = new Wheel();
  30. }
  31. }
  32.  
  33. public static void main(String[] args) {
  34. Car car = new Car();
  35.  
  36. car.getLeft().getWindow().rollDown();
  37. car.getLeft().getWindow().rollUp();
  38. System.out.println();
  39. //Wheel-en belül inflate metód -> tudjuk felfújni
  40. car.getWheel()[0].inflate(99);
  41. System.out.println();
  42. car.getRight().open();
  43. car.getRight().close();
  44. System.out.println();
  45. car.getEngine().start();
  46. car.getEngine().rev();
  47. car.getEngine().stop();
  48. }
  49. }
  50.  
  51. //-------------------------------------------------------------------------------------------------
  52.  
  53. public class Window {
  54.  
  55. public void rollUp() {
  56. System.out.println("The window is rolled up!");
  57. }
  58.  
  59. public void rollDown() {
  60. System.out.println("The window is rolled down!");
  61. }
  62. }
  63.  
  64. //-----------------------------------------------------------------------------------------------------
  65.  
  66. public class Door {
  67.  
  68. private Window window;
  69.  
  70.  
  71. public Door() {
  72.  
  73. this.window = new Window();
  74. }
  75.  
  76. public void open() {
  77. System.out.println("The door is open!");
  78. }
  79.  
  80. public void close() {
  81. System.out.println("The door is closed!");
  82. }
  83.  
  84. public Window getWindow() {
  85. return window;
  86. }
  87. }
  88.  
  89. //-----------------------------------------------------------------------------------------------------------
  90.  
  91. public class Engine {
  92.  
  93. public void start() {
  94. System.out.println("The engine starts");
  95. }
  96.  
  97. public void rev() {
  98. System.out.println("The car moves back");
  99. }
  100.  
  101. public void stop() {
  102. System.out.println("The car stops");
  103. }
  104. }
  105.  
  106. //-------------------------------------------------------------------------------------------------
  107.  
  108. public class Wheel {
  109.  
  110. private int pressure;
  111. private final int MAX_PRESSURE=100;
  112.  
  113. public void inflate(int pressure) {
  114. if(pressure<MAX_PRESSURE){
  115. System.out.println("The wheel is under the right air-pressure!");
  116. }
  117. else System.out.println("The wheel is totally full of air!");
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement