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
8 changes: 6 additions & 2 deletions TIL/sample/2026-06-15-정리.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
▷ ArrayList<Integer, Double, Boolean, Character>로 <>안에 넣어 타입을 참조할 수 있도록 한다.
▷ add()로 데이터 추가
▷ 🥲 get(index)로 꺼냄 || class에서 final 변수 일때에도 get+변수(){}이런 형식으로 작성

- setter 내부에서 타당성 검사
throw new IllegalArgumentException(“메세지");” 를 작성하여 프로그램을 중단

Expand All @@ -41,7 +40,12 @@
{
void 변수
}
- [단축키]
[생성자 오버로드] :: 하나의 생성자 + 타입이 다른 여러 방법의 정의 형태
Hero() {}
Hero(String name) {}
Hero(String name, int hp) {}
Comment on lines +43 to +46

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

생성자 오버로드 예시가 실제 저장소 코드와 불일치합니다.

두 TIL 문서(2026-06-15, 2026-06-16)의 생성자 오버로드 예시는 모두 동일한 근본 원인으로 인한 문제입니다. 제시된 Hero() / Hero(String name) / Hero(String name, int hp) 예시는 현재 저장소의 Hero.java에 존재하지 않으며, 실제 구현은 Hero(int hp) 생성자만 가지고 있습니다. 학습 자료로서 정확성이 중요하므로 두 문서를 모두 수정해 주세요.

  • TIL/sample/2026-06-15-정리.md#L43-L46: 생성자 오버로드 예시를 실제 Hero.java와 일치하도록 수정
  • TIL/sample/2026-06-16-정리.md#L14-L17: 동일하게 예시를 실제 코드와 일치하도록 수정, 또는 더 일반적인 생성자 오버로드 설명으로 변경
📍 Affects 2 files
  • TIL/sample/2026-06-15-정리.md#L43-L46 (this comment)
  • TIL/sample/2026-06-16-정리.md#L14-L17
🤖 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 `@TIL/sample/2026-06-15-정리.md` around lines 43 - 46, The constructor overload
examples in both TIL documents do not match the actual Hero.java implementation.
In TIL/sample/2026-06-15-정리.md (lines 43-46), update the Hero constructor
examples to reflect the actual implementation which only includes Hero(int hp),
rather than the fictional Hero(), Hero(String name), and Hero(String name, int
hp) constructors. In TIL/sample/2026-06-16-정리.md (lines 14-17), make the same
correction to align with the actual Hero.java code, or alternatively replace
both examples with a generic constructor overload pattern that is not tied to
the actual codebase implementation to avoid confusion about what exists in the
repository.

[단축키]

- Ctrl+Alt :: 함수가 작성된 실제 위치로 이동
- shift + F6 :: 이미 정해진 클래스 함수의 이름을 전체 변경하려 할때

Expand Down
75 changes: 75 additions & 0 deletions TIL/sample/2026-06-16-정리.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 2026-06-16

## 오늘 배운 내용

- exdends 상속선언 :: public class SuperHero extends Hero { }
- super() :: 부모 생성자 호출(반드시 첫 줄에) :: public SuperHero(String name, int hp) { super(name, hp); }
- super.메소드() :: 부모 메소드(함수)도 함께 실행하고 싶을때 :: @Override public void attack(Slime slime) { super.attack(slime); }
- @Override :: 부모 메소드(함수)를 자식이 재사용 시 :: @Override public void run() { System.out.println("멋지게 퇴각했다"); }
- final :: 상속/오버라이드 금지가 되는 상수 선언
public final class String { } // 이 클래스는 상속 불가
public final void slip() { } // 이 메소드는 오버라이드 불가
[ 상속 가능 is-a 원칙] :: 자식 is a 부모 와 같이 문장이 자연스러으면 되

[생성자 오버로드 Overload] :: 하나의 생성자 + 타입이 다른 여러 방법의 정의 형태
Hero() {}
Hero(String name) {}
Hero(String name, int hp) {}

️ 🔐📌 초기화 값이 존재하는 부모 클래스 생성자 ➡️ 자식 클래스를 생성 가능
[부모에 덮어쓰기 오버라이드 Override] ::
class Animal {
void speak() { System.out.println("..."); }
}
@Override ◀ 오버라이드(재정의) 할 때 꼭 쓰기

⭐ 자식:: Dog | 부모:: extends Animal ⭐
↓ ↓
class Dog extends Animal {
void speak() { System.out.println("멍멍!"); } // 부모 걸 덮어씀
}
@Override ◀ 오버라이드(재정의) 할 때 꼭 쓰기
class Cat extends Animal {
void speak() { System.out.println("야옹~"); }
}
[⭐⭐ 인스턴트하기 위해서는 생성자가 필요 ⭐⭐] ::
public class Hero { // ← ①클래스
private String name;
private int hp;
public Hero(String name, int hp) { // ← ②생성자
this.name = name;
this.hp = hp;
}
Hero hero = new Hero("홍길동", 100); // ← ③인스턴스
}
Comment on lines +36 to +44

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

코드 샘플이 문법적으로 유효하지 않습니다.

라인 43의 Hero hero = new Hero("홍길동", 100);는 클래스 본체의 최상위 수준에서 직접 statement를 작성한 것으로, Java 컴파일 오류가 발생합니다. 클래스 변수 선언이나 메소드 내부에서만 인스턴스화 코드가 유효합니다.

🔧 권장 수정안

옵션 1: main 메소드 내부로 이동 (추천)

  public class Hero {
    private String name;
    private int hp;
    public Hero(String name, int hp) {
      this.name = name;
      this.hp = hp;
    }
-   Hero hero = new Hero("홍길동", 100);
+   public static void main(String[] args) {
+     Hero hero = new Hero("홍길동", 100);
+   }
  }

옵션 2: 설명 텍스트로 변경

- Hero hero = new Hero("홍길동", 100);
+ // 인스턴스 생성 예시:
+ // Hero hero = new Hero("홍길동", 100);

옵션 3: 인스턴스 생성을 별도 섹션으로 분리

코드 샘플을 클래스 정의 부분과 사용 부분으로 명확히 분리하면 혼동을 줄일 수 있습니다.

🤖 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 `@TIL/sample/2026-06-16-정리.md` around lines 36 - 44, The instance creation
statement Hero hero = new Hero("홍길동", 100); is written at the top level of the
class body, which is invalid Java syntax. Move this instantiation code inside a
method (such as a main method) where executable statements are allowed, or
separate it into a different code example that shows usage outside the class
definition. This will ensure the code sample is syntactically valid and properly
demonstrates both the class definition and its instantiation.

[ getter / setter 주로 쓰는 경우 ] ::

- private 변수 접근할 때
- 값 검증 시
- final 상수는 getter만 사용

[단축키] ::
- Ctrl+Alt :: 함수가 작성된 실제 위치로 이동
- Ctrl+B :: 함수 상속 위치 이동
- shift + F6 :: 이미 정해진 클래스 함수의 이름을 전체 변경하려 할때

## 기억해야 할 내용

- TEST코드 파일은 항상 따로 만들어야 한다
[테스트 파일 생성법]
테스트 할 클래스 변수 클릭 ➡️ Generate ➡️ TEST 선택 ➡️ 해당 파일의 TEST 파일 생성
- ex) WandTest (@Test) 항상 짝궁! 같이 있어야 한다
[순서]
class 테스트이름Test {
@Test
void 테스트메소드() { }

## 실습 코드

```java
public class Cleric {


}
18 changes: 18 additions & 0 deletions game/game.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@startuml
scale 3

class SuperHero exdends Hero{

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

extends 키워드 오타로 다이어그램이 깨집니다.

Line 4의 exdendsextends로 수정해야 PlantUML 상속 관계가 정상 파싱됩니다.

🤖 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/game.puml` at line 4, The PlantUML class inheritance syntax has a typo
in the SuperHero class definition where `exdends` should be `extends`. Correct
the spelling of the keyword from `exdends` to `extends` in the class SuperHero
declaration to ensure the inheritance relationship between SuperHero and Hero is
properly parsed by PlantUML.

+void setFlying(bool flying)
+bool isflying()
}

class Hero{
-int hp
-String name

+void attack()
}

class wizard{}

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

public class Hero {
private int hp;

public Hero(int hp) {
this.hp = hp;
}

public int getHp() {
return hp;
}

public void setHp(int hp) {
this.hp = hp;
}
Comment on lines +14 to +16

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

HP 하한 검증이 없어 전투 로직이 역전될 수 있습니다.

Line 14-16에서 음수 HP를 허용하면, 이후 독 데미지 계산에서 음수 데미지가 발생해 실제로 HP가 증가할 수 있습니다. setHp에서 최소 0으로 clamp(또는 예외 처리)해 상태 무결성을 고정해 주세요.

🤖 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/Hero.java` around lines 14 - 16, The
setHp method in the Hero class lacks lower bound validation, allowing negative
HP values that can cause incorrect battle logic (negative damage becomes
healing). Modify the setHp method to validate and clamp the HP parameter to a
minimum value of 0 before assigning it to the instance variable, or throw an
exception if negative values are provided. This ensures HP state integrity and
prevents reversed damage calculations.


}
7 changes: 1 addition & 6 deletions game/src/main/java/com/survivalcoding/PersonPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ public PersonPerson(String Name, int Age) {

}

//컬렉션

//2장 연습문제 1
//1),3)은 set으로
//2)은 list로

//test 파일을 따로 만들지 않고 여기서 바로 작성한 것
class main {
static void main() {
List<PersonPerson> name = new ArrayList<>();
Expand Down
24 changes: 24 additions & 0 deletions game/src/main/java/com/survivalcoding/PoisonSlime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.survivalcoding;
//Slime (부모) -> Extends Slime(자식)

public class PoisonSlime extends Slime {
private int poisonCnt = 5;

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


@Override
public void attack(Hero hero) {
super.attack(hero);
if (poisonCnt > 0) {
System.out.println("슬라임 " + suffix + " 독 살포!");
int damage = hero.getHp() / 5;
hero.setHp(hero.getHp() - damage);
System.out.println(damage + " 포인트 데미지");
poisonCnt--;
}

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

public class Slime {
final String suffix; //suffix은 슬라임 이름
int hp;

public Slime(String suffix) {
this.suffix = suffix; //값이 초기화 된 부모 생성자 ▶ 자식 클랙스에서 빨간 줄 없이 잘 굴러감
}

void attack(Hero hero) {
System.out.println("==========================");
System.out.println("슬라임 " + suffix + " 이(가) 공격했다");
System.out.println("10 의 데미지");
hero.setHp(hero.getHp() - 10);
System.out.println("--------------------------");
}
}
21 changes: 0 additions & 21 deletions game/src/main/java/com/survivalcoding/all.java

This file was deleted.

17 changes: 17 additions & 0 deletions game/src/test/java/com/survivalcoding/PoisonSlimeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.survivalcoding;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class PoisonSlimeTest {

@Test
void attack() {
Hero h = new Hero(100);
PoisonSlime ps = new PoisonSlime("홍길홍길");
ps.attack(h);
assertEquals(72, h.getHp());
System.out.println("==========================");
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}