From 05132e6d9e6fa7f4330a490e12d9a0ce1a37f766 Mon Sep 17 00:00:00 2001 From: kdy9960 <146910663+kdy9960@users.noreply.github.com> Date: Tue, 31 Oct 2023 00:06:38 +0900 Subject: [PATCH] =?UTF-8?q?2=EB=B2=88=EC=A7=B8=20=EB=B3=B4=EC=B6=A9=20?= =?UTF-8?q?=EA=B3=BC=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/daeyoung/src/Main.java | 39 ++++++++++++++++++++-- src/daeyoung/src/base/Car.java | 49 ++++++++++++++++++++++++++++ src/daeyoung/src/base/House.java | 55 ++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 src/daeyoung/src/base/Car.java create mode 100644 src/daeyoung/src/base/House.java diff --git a/src/daeyoung/src/Main.java b/src/daeyoung/src/Main.java index 60c8159..2078b1d 100644 --- a/src/daeyoung/src/Main.java +++ b/src/daeyoung/src/Main.java @@ -1,11 +1,46 @@ +import base.Car; import base.Case1; +import java.util.ArrayList; +import java.util.List; + // Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, // then press Enter. You can now see whitespace characters in your code. public class Main { public static void main(String[] args) { - Case1 main = new Case1(); - main.gameStart(6); +// Case1 case1 = new Case1(); +// case1.gameStart(3); + + + List carList = new ArrayList<>(); + Car bluecar = new Car("파란 차"); + // 여기서 new Car 는 Car 클래스의 12번째줄의 생성자 Car를 따른다 + Car blackcar = new Car("검정색 차", "제네시스", 258, "가솔린"); + // 여기서 new Car 는 Car 클래스의 20번째줄의 생성자 Car를 따른다 + +// for (Integer i = 0 ; i < 10 ; i ++) { // 범위형태로 list 만들수 있음, 이러면 더미 데이터로 들어감 +// carList.add(new Car("아무거나")); +// } + + carList.add(bluecar); // carList 안에 bluecar를 넣어주는것, List안에 일일히 적어서 넣어주어야 한다. + carList.add(blackcar); + +// for(Car car : carList) { +// System.out.println(car.무슨색차니()); // +// System.out.println(car.무슨브랜드와무슨색을가지고있니()); +// } + + + for(Integer i = 0 ; i < 10 ; i++) { + bluecar.가속하기(); + } + + + + for(Car car : carList) { + System.out.println(car.무슨색차니() + " 현재 차의 속력은 " + car.현재속력은()); + } + } diff --git a/src/daeyoung/src/base/Car.java b/src/daeyoung/src/base/Car.java new file mode 100644 index 0000000..402fcc7 --- /dev/null +++ b/src/daeyoung/src/base/Car.java @@ -0,0 +1,49 @@ +package base; + +public class Car { + // 밑에 내용들은 Car라는 속성의 변수다 + static Integer WHEEL_COUNT = 4; + private String color; + private String brand; + private Integer maxSpeed; + private Integer currentSpeed; + private String fuel; + + public Car(String inputcolor) { + this.color = inputcolor; + this.brand = "테슬라"; + this.maxSpeed = 250; + this.fuel = "전기"; + this.currentSpeed = 0; + } + + public Car(String inputcolor, String inputBrand, Integer inputmaxSpeed, String inputfuel) { + this.color = inputcolor; + this.brand = inputBrand; + this.maxSpeed = inputmaxSpeed; + this.fuel = inputfuel; + this.currentSpeed = 0; + } + + public String 무슨색차니(){ + return "색은 " + this.color; + } + + public String 무슨브랜드와무슨색을가지고있니(){ + return "브랜드는 " + this.brand + " 색은 " + this.color; + } + + public void 가속하기 () { + this.currentSpeed += 1; + } + + public void 감속하기 () { + this.currentSpeed -= 1; + } + + public Integer 현재속력은() { + return this.currentSpeed; + } + + +} diff --git a/src/daeyoung/src/base/House.java b/src/daeyoung/src/base/House.java new file mode 100644 index 0000000..7a2fc47 --- /dev/null +++ b/src/daeyoung/src/base/House.java @@ -0,0 +1,55 @@ +package base; + +public class House { + + static Integer Window = 5; + private String Brand; + private String Kind; + private Integer Area; + private Integer Floor; + private Integer Elevator; + + public House(String inputBrand, String inputKind, Integer inputArea, Integer inputFloor) { + this.Brand = inputBrand; + this.Kind = inputKind; + this.Area = inputArea; + this.Floor = inputFloor; + this.Elevator = 0; + } + + public House(Integer inputArea) { + this.Brand = "삼성"; + this.Kind = "아파트"; + this.Area = inputArea; + this.Floor = 5; + this.Elevator = 0; + } + + public String 건물_브랜드가무엇이니() { + return this.Brand; + } + + public Integer 집면적이_얼마나되니() { + return this.Area; + } + + public Integer 이건물의_층수는() { + return this.Floor; + } + + public Integer 엘레베이터_현재위치는() { + return this.Elevator; + } + + public void 엘레베이터_올라가기() { + this.Elevator += 1; + } + + public void 엘레베이터_내려가기() { + this.Elevator -= 1; + } + + + + +}