Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TIL/sample/2026-06-15-캡슐-컬렉션.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Set : 순서가 없는 집합 (중복 불가)
- 컬렉션은 기본형(int, double, boolean 등)을 취급할 수 없다

## 기억할 것
## 기억할 것-

- 멤버에 대한 접근 : 필드는 private 메소드는 public 클래스 엑세스 지정은 public로 알괄 지정, package private 지정 멤버나 클래스는 통일 패키지내의 클래스에서만 접근 가능
- 리스트와 배열을 비슷 하지만 서로 차이가 있다. 배열은 처음 선언시 메모리 공간이 고정적이고, 리스트는 가변적으로 지정 가능(데이터가 추가 또는 삭제 될 때 크기를 동적으로 늘리거나 줄어듬)
Expand Down
145 changes: 145 additions & 0 deletions TIL/sample/2026-06-16-상속.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# 2026-06-08 함수

## 오늘 배운 내용

- 상속/
이전의 만든 클래스와 닮았지만 일부 다른 클래스
이전의 만든 클래스에서 함수를 불러옴
- 기존의 복사 붙여 넣기/
추가, 수정에 시간이 걸리고 소스의 파악이나 관리가 어려워 진다. -> 그래서 나온 해결책이 상속
- 오버라이드/ 부모 클래스의 메서드를 자식 클래스에서 재 작성 할 경우 오버라이드(override)라 부름

- 인스턴스/
인스턴스는 내부에 부모클래스의 인스턴스를 가지는 다중구조를 가진다.
보다 외측의 인스턴스에 속하는 메소드가 우선적으로 동작한다.
외측의 인스턴스에 속하는 메소드는 super 을 사용하여 내측 인스턴스의 멤버에 점근할 수 있다.
- super()/ super는 부모 클래스를 가리키는 키워드. 부모 기능을 유지하면서 추가 기능을 덧 붙일 때 사용.
- 생성자 동작/ 다중구조의 인스턴스가 생성되는데, JVM 는 자동적으로 가장 외측 인스턴스의 생성자를 호출.
모든 생성자는, “부모 인스턴스의 생성자"를 호출 할 필요가 있다.
생성자의 선두에 super() 가 없으면, 암묵적인 “super();” 가 추가 됨.

## 기억할 것

```java
public class Hero {
public Hero() {
System.out.println("Hero 생성자");
}
}

public class superHero extends Hero {
public superHero() {
System.out.println("superHero 생성자");
}
}

public calss Main{

public static void main(String[] args) {
SuperHero superHero = new SuperHero();
}
}
//이런 상황에서
//Hero 생성자 먼저 출력 후 superHero 생성자 다음 출력
```

- extends로 클래스 상속을 표시
- super는 반드시 생성자 첫줄에 쓴다
- is a 원칙 (~은(는) 이다.)/
한 클래스와 다른 클래스의 상속 관계를 a는 b에 속해 있다는 것으로 표기하면 이해하기 쉽다.
개념적으로 관계성이 없는 상속은 잘못된 상속.
- 자식 클래스는 구체화, 부모 클래스는 추상화 (예: 부모 클래스로 엔진/ 자식 클래스로 자동차, 배, 비행기, 로켓)

## 실습 코드

```java
public class Wizard {
private int hp;
private int mp;
//private int mp = 100;
private String name;
private Wand wand;

public void wizard(int mp) {
//if (this.mp < mp) {
this.mp = mp;
//}
}

public void heal(Hero hero) {
if (this.mp <= 0) {
System.out.println("마나가 부족합니다.");
}
this.mp -= 10;
hero.setHp(hero.getHp() + 20);
System.out.println("힐을 시전 하였습니다. 대상 HP: " + hero.getHp());
}

public void setMp(int mp) {
this.mp = mp;
}

public int getMp() {
return mp;
}

}

public class GreatWizard extends Wizard {
int mp = 150;

public GreatWizard(int mp) {
super.wizard(mp);
}


public void heal(Hero hero) {
super.heal(hero);
super.setMp(getMp() + 5);
hero.setHp(hero.getHp() + 5);
}

public void superHeal(Hero hero) {
super.setMp(getMp() - 40);
hero.maxHp();
System.out.println("슈퍼 힐을 시전 했습니다. 대상 HP: " + hero.getHp());
}
}

class WandTest {
@Test
@DisplayName("마법사 테스트")
void test() {
//given
Hero hero = new Hero();
GreatWizard greatWizard = new GreatWizard(150);
//when 1
for (int i = 0; i < 5; i++) {
greatWizard.heal(hero);
}
//then 1
assertEquals(225, hero.getHp());
//when 2
greatWizard.superHeal(hero);
//then 2
assertEquals(100, hero.getHp());
}

}


```

## 어려웠던 점

- is a 원칙대로 클래스 이름을 정의 하려고 하니 단어가 잘 생각이 안난다.
- 사실상 상속 개념을 처음으로 실습해서 부모 클래스에서 만든 메서드를 지속해서 망각 했다.

## 해결 방법

- AI를 통해 단어들을 찾거나 인터넷에 검색을 하여 클래스 이름을 검색 하였다.
- 교보재 보면서 천천히 코드를 작성 했다.

## 내일 더 공부할 것

- 클래스 상속 활용 방법
39 changes: 39 additions & 0 deletions game/src/game.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@startuml

class Hero {
- name: String
- hp: int
- maxHP: int
--
+ maxHp()
+ setHp(hp: int)
+ getHp(): int
+ setRandomMoney() {static}
}

class Wizard {
- hp: int
- mp: int
- name: String
- wand: Wand
--
+ wizard(mp: int)
+ heal(hero: Hero)
+ setMp(mp: int)
+ getMp(): int
+ getHp(): int
+ setHp(hp: int)
}
Comment on lines +20 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

UML 공개 API가 현재 코드와 불일치합니다.

WizardgetHp()/setHp()는 활성 구현이 없고, Hero.getHp()도 현재 접근수준과 UML 표기가 맞지 않습니다. 다이어그램을 실제 코드 기준으로 동기화해 주세요.

수정 예시
 class Hero {
@@
-  + getHp(): int
+  ~ getHp(): int
@@
 class Wizard {
@@
-  + getHp(): int
-  + setHp(hp: int)
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/game.puml` around lines 20 - 26, The UML diagram in
game/src/game.puml shows public API methods for the Wizard and Hero classes that
do not match the actual code implementation. Remove getHp() and setHp(hp: int)
from the Wizard class definition in the diagram since they have no active
implementation in the actual Wizard code. Additionally, update the access level
notation for Hero.getHp() in the diagram to match the actual access level of the
method in the Hero class implementation. Ensure all method signatures and
visibility modifiers in the UML diagram accurately reflect what is actually
implemented in the code.


class GreatWizard extends Wizard {
- mp: int
--
+ GreatWizard(mp: int)
+ heal(hero: Hero)
+ superHeal(hero: Hero)
}

Wizard ..> Hero : heal(hero)
GreatWizard ..> Hero : heal(hero)

@enduml
22 changes: 22 additions & 0 deletions game/src/main/java/com/survivalcoding/GreatWizard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.survivalcoding;

public class GreatWizard extends Wizard {
int mp = 150;

public GreatWizard(int mp) {
super.wizard(mp);
}


public void heal(Hero hero) {
super.heal(hero);
super.setMp(getMp() + 5);
hero.setHp(hero.getHp() + 5);
}

public void superHeal(Hero hero) {
super.setMp(getMp() - 40);
hero.maxHp();
System.out.println("슈퍼 힐을 시전 했습니다. 대상 HP: " + hero.getHp());
}
}
25 changes: 17 additions & 8 deletions game/src/main/java/com/survivalcoding/Hero.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.Random;

public class Hero {
public String name;
public int hp;
private String name;
private int hp = 0;
private int maxHP = 100;
//Sword sword;
static int money = 100;

Expand All @@ -15,12 +16,21 @@ static void setRandomMoney() {
hero.name = "홍길동";
}

public void maxHp() {
this.hp = maxHP;
}

//setter 값을 입력
void setHp(int hp) {
public void setHp(int hp) {

this.hp = hp;
}

// getter 값을 불러오기
int getHp() {
return hp;
}

void setName(String name) {
if (name == null) {
throw new IllegalArgumentException("이름이 null 일 수는 없습니다.");
Expand All @@ -31,11 +41,6 @@ void setName(String name) {
this.name = name;
}

// getter 값을 불러오기
int getHp() {
return hp;
}

Hero() {
this.name = "홍길동";

Expand All @@ -52,4 +57,8 @@ void attack() {
hp -= 1;
System.out.println("공격했다");
}

void heroRun() {
System.out.println("RUN");
}
}
13 changes: 7 additions & 6 deletions game/src/main/java/com/survivalcoding/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ public class Main {
public static void main(String[] args) {

//용사 생성 (ram 메모리에 용사 데이터 올리기)
Hero hero = new Hero();

hero.setName("");

//Hero.hp = 10;

// Hero hero = new Hero();
// Wizard wizard = new GreatWizard(100);
//
//
// for (int i = 0; i < 20; i++) {
// wizard.heal(hero);
// }
}
}
14 changes: 7 additions & 7 deletions game/src/main/java/com/survivalcoding/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static void main(String[] args) {


ArrayList<String> names = new ArrayList<>();
names.add("홍길동");
names.add("한석봉");
names.add("HONGGILDONG");
names.add("HANSUKBONG");

Iterator<String> it = names.iterator();
while (it.hasNext()) {
Expand All @@ -28,19 +28,19 @@ public static void main(String[] args) {

//컬렉션 2
List<Person> people = new ArrayList<>();
people.add(new Person("홍길동", 20));
people.add(new Person("한석봉", 25));
people.add(new Person("HONGGILDONG", 20));
people.add(new Person("HANSUKBONG", 25));

for (Person person : people) {
System.out.println(person.getName() + "의 나이는 " + person.getAge() + "");
System.out.println(person.getName() + "'s age is " + person.getAge() + "years old");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

출력 문자열 공백 누락 수정 필요

Line [35]에서 person.getAge()"years old" 사이 공백이 빠져 출력이 25years old처럼 붙어 보입니다. 사용자 메시지 포맷을 바로잡는 것이 좋습니다.

수정 제안
-            System.out.println(person.getName() + "'s age is " + person.getAge() + "years old");
+            System.out.println(person.getName() + "'s age is " + person.getAge() + " years old");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
System.out.println(person.getName() + "'s age is " + person.getAge() + "years old");
System.out.println(person.getName() + "'s age is " + person.getAge() + " years old");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/Person.java` at line 35, In the
System.out.println statement, add a missing space between person.getAge() and
the string "years old". Currently the concatenation produces output like
"25years old" without a space. Modify the string literal from "years old" to "
years old" (with a leading space) to ensure proper spacing in the output.

}
}

private String getName() {
String getName() {
return name;
}

private int getAge() {
int getAge() {
return age;
}

Expand Down
23 changes: 23 additions & 0 deletions game/src/main/java/com/survivalcoding/PoisonSlime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.survivalcoding;

public class PoisonSlime extends Slime {

private int poisonCount = 5;

public PoisonSlime(String suffix) {
super(suffix);
}

public void poisonSlimeAttack(Hero hero) {
super.attack(hero);

if (poisonCount <= 0) {
System.out.println("독포자를 살포 했다!");
int poisonDamage = hero.getHp() / 5;
hero.setHp(hero.getHp() - poisonDamage);
System.out.println(poisonDamage + " 포인트 데미지");

}
poisonCount--;
Comment on lines +14 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

독 공격 발동 조건이 반대로 되어 있어 사용 횟수 제한이 깨집니다.

Line 14의 poisonCount <= 0 때문에 독 데미지가 초기 5회가 아니라 이후부터 발동하고, Line 21에서 계속 감소해 음수 구간에서도 매번 독 데미지가 적용됩니다. 카운트 기반이라면 poisonCount > 0일 때만 발동/감소해야 합니다.

수정 예시
     public void poisonSlimeAttack(Hero hero) {
         super.attack(hero);

-        if (poisonCount <= 0) {
+        if (poisonCount > 0) {
             System.out.println("독포자를 살포 했다!");
             int poisonDamage = hero.getHp() / 5;
             hero.setHp(hero.getHp() - poisonDamage);
             System.out.println(poisonDamage + " 포인트 데미지");
-
+            poisonCount--;
         }
-        poisonCount--;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (poisonCount <= 0) {
System.out.println("독포자를 살포 했다!");
int poisonDamage = hero.getHp() / 5;
hero.setHp(hero.getHp() - poisonDamage);
System.out.println(poisonDamage + " 포인트 데미지");
}
poisonCount--;
if (poisonCount > 0) {
System.out.println("독포자를 살포 했다!");
int poisonDamage = hero.getHp() / 5;
hero.setHp(hero.getHp() - poisonDamage);
System.out.println(poisonDamage + " 포인트 데미지");
poisonCount--;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/PoisonSlime.java` around lines 14 - 21,
The poison attack condition in the PoisonSlime class is inverted, breaking the
usage limit. The condition at line 14 checks if poisonCount <= 0, but it should
check if poisonCount > 0 to ensure poison damage only triggers when uses remain.
Additionally, the poisonCount decrement at line 21 happens outside the if block,
causing it to decrease even when no poison is used. Move the poisonCount--
statement inside the if block so the counter only decreases when the poison
attack actually triggers, ensuring exactly 5 uses before the attack becomes
unavailable.

}
}
Loading