From 0662b6f508d8938c3e8c76ca9ec4a804ffbd8811 Mon Sep 17 00:00:00 2001 From: toychip Date: Wed, 14 Feb 2024 04:22:36 +0900 Subject: [PATCH] =?UTF-8?q?[Week3][Chap11]=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=9C3=20(#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/week3/poly/car1/Car.java" | 7 ++++++ .../main/java/week3/poly/car1/CarMain1.java" | 22 +++++++++++++++++++ .../main/java/week3/poly/car1/Driver.java" | 18 +++++++++++++++ .../src/main/java/week3/poly/car1/K3Car.java" | 18 +++++++++++++++ .../main/java/week3/poly/car1/Model3Car.java" | 18 +++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Car.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/CarMain1.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Driver.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/K3Car.java" create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Model3Car.java" diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Car.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Car.java" new file mode 100644 index 0000000..840c414 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Car.java" @@ -0,0 +1,7 @@ +package week3.poly.car1; + +public interface Car { + void startEngine(); + void offEngine(); + void pressAccelerator(); +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/CarMain1.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/CarMain1.java" new file mode 100644 index 0000000..8461b71 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/CarMain1.java" @@ -0,0 +1,22 @@ +package week3.poly.car1; + +public class CarMain1 { + public static void main(String[] args) { + Driver driver = new Driver(); + + // k3 선택 + K3Car k3Car = new K3Car(); + driver.setCar(k3Car); + driver.drive(); + + // 차량 변경(k3 -> model3) + Model3Car model3Car = new Model3Car(); + driver.setCar(model3Car); + driver.drive(); + + //차량 변경(model3 -> newCar) + NewCar newCar = new NewCar(); + driver.setCar(newCar); + driver.drive(); + } +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Driver.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Driver.java" new file mode 100644 index 0000000..4fe643f --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Driver.java" @@ -0,0 +1,18 @@ +package week3.poly.car1; + +public class Driver { + + private Car car; + + public void setCar(Car car) { + System.out.println("자동차를 설정합니다: " + car); + this.car = car; + } + + public void drive() { + System.out.println("자동차를 운전합니다."); + car.startEngine(); + car.pressAccelerator(); + car.offEngine(); + } +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/K3Car.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/K3Car.java" new file mode 100644 index 0000000..e12a51e --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/K3Car.java" @@ -0,0 +1,18 @@ +package week3.poly.car1; + +public class K3Car implements Car { + @Override + public void startEngine() { + System.out.println("K3Car.startEngine"); + } + + @Override + public void offEngine() { + System.out.println("K3Car.offEngine"); + } + + @Override + public void pressAccelerator() { + System.out.println("K3Car.pressAccelerator"); + } +} diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Model3Car.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Model3Car.java" new file mode 100644 index 0000000..904ea85 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car1/Model3Car.java" @@ -0,0 +1,18 @@ +package week3.poly.car1; + +public class Model3Car implements Car { + @Override + public void startEngine() { + System.out.println("Model3Car.startEngine"); + } + + @Override + public void offEngine() { + System.out.println("Model3Car.offEngine"); + } + + @Override + public void pressAccelerator() { + System.out.println("Model3Car.pressAccelerator"); + } +}