From 573a1aadc72820c0186105073377237eaad144eb Mon Sep 17 00:00:00 2001 From: mj Date: Mon, 29 Jun 2026 17:34:26 +0900 Subject: [PATCH] enum, Generic --- .../2026-06-30-\354\240\225\353\246\254.md" | 28 +++++++ ...54\240\225\353\246\254\360\237\223\214.md" | 0 game/june22th.puml | 2 +- game/june23th.puml | 80 +++++++++++++++++++ game/june30th.puml | 19 +++++ .../main/java/com/survivalcoding/Book2.java | 78 ++++++++++++++++++ post-oop/build.gradle | 20 +++++ post-oop/june30th.puml | 22 +++++ .../java/com/survivalcoding/StrongBox.java | 63 +++++++++++++-- .../com/survivalcoding/StrongBoxTest.java | 26 +++--- settings.gradle | 1 - 11 files changed, 318 insertions(+), 21 deletions(-) create mode 100644 "TIL/sample/2026-06-30-\354\240\225\353\246\254.md" rename "TIL/sample/2026-06-29-\354\240\225\353\246\254.md" => "TIL/sample/\360\237\223\2142026-06-29-\354\240\225\353\246\254\360\237\223\214.md" (100%) create mode 100644 game/june23th.puml create mode 100644 game/june30th.puml create mode 100644 game/src/main/java/com/survivalcoding/Book2.java create mode 100644 post-oop/build.gradle create mode 100644 post-oop/june30th.puml diff --git "a/TIL/sample/2026-06-30-\354\240\225\353\246\254.md" "b/TIL/sample/2026-06-30-\354\240\225\353\246\254.md" new file mode 100644 index 0000000..a16cf4b --- /dev/null +++ "b/TIL/sample/2026-06-30-\354\240\225\353\246\254.md" @@ -0,0 +1,28 @@ +# 2026-06-30 + +## 오늘 배운 내용 +검색이 LISt는 느려 || SET/MAP은 빠르다 +h1 == h2 는 서로 다른 주소이므로 '=='가 들어갔어도 비교는 equals로 한다 +ㄴ> 비교하는 코드 틀 :: [h1.compareTo(h2)] +[equals() 특징] :: equals가 있으면 같은 내용은 지워진다 + +[얕은 복사 (주소만 복사) || 깊은 복사(주소 달라, 내용 같아)] +[얕은 복사 코드의 틀 ] :: Book h2 = h1.clone(); +[깊은 복사 코드의 틀 ] :: copy.author = this.author.clone(); + +[ 단축키 ] + +- Ctrl+Alt :: 함수가 작성된 실제 위치로 이동 +- Ctrl+B :: 함수 자세히 보기 +- Ctrl+H :: 상속관계 보기 +- shift + F6 :: 이미 정해진 클래스 함수의 이름을 전체 변경하려 할때 +- Alt+Enter :: 자동생성 +- ctrl+shift+T :: TEST 파일 생성 + +## 실습 코드 + +```java +public class Cleric { + + +} diff --git "a/TIL/sample/2026-06-29-\354\240\225\353\246\254.md" "b/TIL/sample/\360\237\223\2142026-06-29-\354\240\225\353\246\254\360\237\223\214.md" similarity index 100% rename from "TIL/sample/2026-06-29-\354\240\225\353\246\254.md" rename to "TIL/sample/\360\237\223\2142026-06-29-\354\240\225\353\246\254\360\237\223\214.md" diff --git a/game/june22th.puml b/game/june22th.puml index b1258e6..90ec944 100644 --- a/game/june22th.puml +++ b/game/june22th.puml @@ -1,5 +1,5 @@ @startuml -scale 1 +scale 0.7 abstract class Asset { - String name; + Asset(String name) diff --git a/game/june23th.puml b/game/june23th.puml new file mode 100644 index 0000000..6d16f01 --- /dev/null +++ b/game/june23th.puml @@ -0,0 +1,80 @@ +@startuml +'https://plantuml.com/sequence-diagram +size 0.5 + + +class Medic{ +- int healing +} +class Marine{ +-int damege +} +class Trank{ +-int damage +} +class Vulture{ +-int damage +} +class Scv{ +-int damage +} +class Zergling{ +-int damage +} +class Hydra{ +- int damege +} +class Dragun{ +-int damege +} +class Zealot{ +- int damege +} + + +interface cure{ ++ int getHeal() ++ void setHeal(int healing) +} + +interface unit{} + +interface Mechanic{ ++repairable() +} + +interface Fix{ ++int getFix() ++void setFix(int damege) +} + +interface Attack{} + +abstract Terran{ +-String name +-int HP +} + +abstract Zerg{ +-String name +-int HP +} + +abstract Protoss{ +-String name +-int HP +} + +interface Bionic{} + +interface Mineral{} + +interface NoLiving{} + +interface Structure{} + +interface Moveable{} + + + +@enduml \ No newline at end of file diff --git a/game/june30th.puml b/game/june30th.puml new file mode 100644 index 0000000..ece0e51 --- /dev/null +++ b/game/june30th.puml @@ -0,0 +1,19 @@ +@startuml + + ++ class Book2 { + - String title; + - Data publishDate; + - String comment; + + + String getTitle() + + void setTitle(String title) + + Data getPublishDate() + + void setPublishDate(Data publishDate) + + String getComment() + + void setComment(String comment) + + +} + +@enduml \ No newline at end of file diff --git a/game/src/main/java/com/survivalcoding/Book2.java b/game/src/main/java/com/survivalcoding/Book2.java new file mode 100644 index 0000000..fa82647 --- /dev/null +++ b/game/src/main/java/com/survivalcoding/Book2.java @@ -0,0 +1,78 @@ +package com.survivalcoding; +import javax.xml.crypto.Data; +import java.util.Objects; + + + +public class Book2 { + private String title; + private Data publishDate; + private String comment; + + Book2(String title, Data publishDate, String comment) { + this.title = title; + this.publishDate = publishDate; + this.comment = comment; + } + + + + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Data getPublishDate() { + return publishDate; + } + + public void setPublishDate(Data publishDate) { + this.publishDate = publishDate; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + + + + + @Override + public boolean equals(Object obj) { + + if (!(obj instanceof Book2)) return false; + Book2 bb = (Book2) obj; + String Data; + return title == bb.title && Data(equals(bb.Data)); + title.equals(Data); + + //boolean Object; + } + + @Override + public int hashCode() { + return Objects.hash(title, publishDate, comment); + } + + @Override + public String toString() { + return "Book2{" + + "title='" + title + '\'' + + ", publishDate=" + publishDate + + ", comment='" + comment + '\'' + + '}'; + } +} + + + + diff --git a/post-oop/build.gradle b/post-oop/build.gradle new file mode 100644 index 0000000..b9a9d5e --- /dev/null +++ b/post-oop/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'java' +} + +group = 'com.survivalcoding' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:6.0.0') + testImplementation 'org.junit.jupiter:junit-jupiter' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/post-oop/june30th.puml b/post-oop/june30th.puml new file mode 100644 index 0000000..62e7f2a --- /dev/null +++ b/post-oop/june30th.puml @@ -0,0 +1,22 @@ +@startuml +enum KeyType { + PADLOCK, + BUTTON, + DIAL, + FINGER +} +class StrongBox { + + - K data + - int cnt + - KeyType keyType + + + StrongBox(KeyType keyType) + + void put(K data) + + K get() +} + +StrongBox -- KeyType +@enduml + + diff --git a/post-oop/src/main/java/com/survivalcoding/StrongBox.java b/post-oop/src/main/java/com/survivalcoding/StrongBox.java index e8e32cb..1581027 100644 --- a/post-oop/src/main/java/com/survivalcoding/StrongBox.java +++ b/post-oop/src/main/java/com/survivalcoding/StrongBox.java @@ -3,17 +3,66 @@ import org.w3c.dom.ls.LSOutput; //제너릭 클래스 선언 -public class StrongBox -{ +public class StrongBox { + /* + private final int PADLOCK = 1024; + private final int BUTTON = 10000; + private final int DIAL = 30000; + private final int FINGER = 1000000; + */ private K data; + private int cnt = 0; //0을 안해도 프리미엄 타입은 자동으로 0으로 설정되어있음 + // private int maxCnt=0; + private KeyType keyType; - public void put(K date){ - this. data = date; + + public void put(K date) { + this.data = date; //count ++; } - public K get(){ - return this.data; + + public StrongBox(KeyType keyType) { + this.keyType = keyType; } -} + public K get() { + cnt++; + //KeyType keyType = KeyType.PADLOCK; //private로 존재하고 생성자로도 저장해놓았으므로 필요 없다. + /*문법은 맞으나 문제의 요구 사항에 충족되지 않아 안되 + if (cnt == PADLOCK) + { + return this.data; + } + else if(cnt == BUTTON) + { + return this.data; + } + else if(cnt == DIAL) + { + return this.data; + } + else if(cnt == FINGER) + + */ + if (keyType == KeyType.PADLOCK) { + if (cnt >= 1024) { + return data; + } + } else if (keyType == KeyType.BUTTON) { + if (cnt >= 10000) { + return data; + } + } else if (keyType == KeyType.DIAL) { + if (cnt >= 30000) { + return data; + } + } else if (keyType == KeyType.FINGER) { + if (cnt >= 1000000) { + return data; + } + } + + return null; //이 부분이 else가 되므로 else를 안 쓴다 + } +} \ No newline at end of file diff --git a/post-oop/src/test/java/com/survivalcoding/StrongBoxTest.java b/post-oop/src/test/java/com/survivalcoding/StrongBoxTest.java index c23ad29..094b590 100644 --- a/post-oop/src/test/java/com/survivalcoding/StrongBoxTest.java +++ b/post-oop/src/test/java/com/survivalcoding/StrongBoxTest.java @@ -1,23 +1,25 @@ package com.survivalcoding; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - import static org.junit.jupiter.api.Assertions.*; -class StrongBoxTest -{ +class StrongBoxTest { @Test - void main() { - StrongBox strongBox = new StrongBox(); - class StrongBox { - integer sb; - void put(integer sb) { this.sb=sb;} - integer get() { return this.sb;} + void test() { + + StrongBox box = + new StrongBox<>(KeyType.PADLOCK); + + box.put(100); + + for (int i = 0; i < 1023; i++) { + assertNull(box.get()); } + + assertEquals(100, box.get()); + } - assertEqauls(); -} +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 583abf0..ef4d2e3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,4 @@ rootProject.name = 'polytech_java2' include 'day01-basic' include 'game' -include 'game:post-oop' include 'post-oop' \ No newline at end of file