Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Car {
- private Engine engine = new Engine();
- private Wheel[] wheel = new Wheel[4];
- private Door left = new Door();
- private Door right = new Door(); // 2-door
- public Engine getEngine() {
- return engine;
- }
- public Wheel[] getWheel() {
- return wheel;
- }
- public Door getLeft() {
- return left;
- }
- public Door getRight() {
- return right;
- }
- public Car() {
- for(int i = 0; i < 4; i++) {
- wheel[i] = new Wheel();
- }
- }
- public static void main(String[] args) {
- Car car = new Car();
- car.getLeft().getWindow().rollDown();
- car.getLeft().getWindow().rollUp();
- System.out.println();
- //Wheel-en belül inflate metód -> tudjuk felfújni
- car.getWheel()[0].inflate(99);
- System.out.println();
- car.getRight().open();
- car.getRight().close();
- System.out.println();
- car.getEngine().start();
- car.getEngine().rev();
- car.getEngine().stop();
- }
- }
- //-------------------------------------------------------------------------------------------------
- public class Window {
- public void rollUp() {
- System.out.println("The window is rolled up!");
- }
- public void rollDown() {
- System.out.println("The window is rolled down!");
- }
- }
- //-----------------------------------------------------------------------------------------------------
- public class Door {
- private Window window;
- public Door() {
- this.window = new Window();
- }
- public void open() {
- System.out.println("The door is open!");
- }
- public void close() {
- System.out.println("The door is closed!");
- }
- public Window getWindow() {
- return window;
- }
- }
- //-----------------------------------------------------------------------------------------------------------
- public class Engine {
- public void start() {
- System.out.println("The engine starts");
- }
- public void rev() {
- System.out.println("The car moves back");
- }
- public void stop() {
- System.out.println("The car stops");
- }
- }
- //-------------------------------------------------------------------------------------------------
- public class Wheel {
- private int pressure;
- private final int MAX_PRESSURE=100;
- public void inflate(int pressure) {
- if(pressure<MAX_PRESSURE){
- System.out.println("The wheel is under the right air-pressure!");
- }
- else System.out.println("The wheel is totally full of air!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement