From cf23e078d94b1bd566d61ad4f5fd1016c60f3bd9 Mon Sep 17 00:00:00 2001 From: arinming Date: Tue, 6 Feb 2024 18:33:34 +0900 Subject: [PATCH] =?UTF-8?q?[Week3][Chap12]=20=EB=8B=A4=ED=98=95=EC=84=B1?= =?UTF-8?q?=20-=20=EC=97=AD=ED=95=A0=EA=B3=BC=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EC=98=88=EC=A0=9C2=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java-basic/src/poly/car0/CarMain0.java" | 6 ++++++ .../java-basic/src/poly/car0/Driver.java" | 18 +++++++++++++++--- .../java-basic/src/poly/car0/Model3Car.java" | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Model3Car.java" diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/CarMain0.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/CarMain0.java" index 767c3d2..7c5fd53 100644 --- "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/CarMain0.java" +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/CarMain0.java" @@ -7,5 +7,11 @@ public static void main(String[] args) { driver.setK3Car(k3Car); driver.drive(); + + // 추가 + Model3Car model3Car = new Model3Car(); + driver.setK3Car(null); + driver.setModel3Car(model3Car); + driver.drive(); } } diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Driver.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Driver.java" index e3719c4..ffc5cc0 100644 --- "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Driver.java" +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Driver.java" @@ -3,15 +3,27 @@ public class Driver { private K3Car k3Car; + private Model3Car model3Car; // 추가 public void setK3Car(K3Car k3Car) { this.k3Car = k3Car; } + // 추가 + public void setModel3Car(Model3Car model3Car) { + this.model3Car = model3Car; + } + public void drive() { System.out.println("자동차를 운전합니다."); - k3Car.startEngine(); - k3Car.pressAccelerator(); - k3Car.offEngine(); + if (k3Car != null) { + k3Car.startEngine(); + k3Car.pressAccelerator(); + k3Car.offEngine(); + } else if (model3Car != null) { + model3Car.startEngine(); + model3Car.pressAccelerator(); + model3Car.offEngine(); + } } } diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Model3Car.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Model3Car.java" new file mode 100644 index 0000000..e1826b6 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Model3Car.java" @@ -0,0 +1,14 @@ +package poly.car0; + +public class Model3Car { + public void startEngine() { + System.out.println("Model3Car.startEngine"); + } + public void offEngine() { + System.out.println("Model3Car.offEngine"); + } + + public void pressAccelerator() { + System.out.println("Model3Car.pressAccelerator"); + } +}