Skip to content

260616_18_서수현#58

Open
SeoSuHyeon1213 wants to merge 4 commits into
SurvivalCodingCampus:student/18_서수현from
SeoSuHyeon1213:master
Open

260616_18_서수현#58
SeoSuHyeon1213 wants to merge 4 commits into
SurvivalCodingCampus:student/18_서수현from
SeoSuHyeon1213:master

Conversation

@SeoSuHyeon1213

Copy link
Copy Markdown

260616_18_서수현

📝 과제 정보

  • 교육 주제: 상속
  • 기존의 클래스를 받아와 새로운 클래스를 만드는 방식
  • 복사, 붙여 넣기 방식으로는 추가, 수정에 시간이 걸리고 소스의 파악이나 관리가 어려워 지는 문제가 있다.

📋 체크리스트

  • 코드 컨벤션 준수 (Formatter 적용)
  • 모든 테스트 케이스 통과 (JUnit)

📷 실행 결과 (또는 테스트 결과)

스크린샷 2026-06-16 171240

❓질문 및 어려웠던 점

  • is a 원칙대로 클래스 이름을 정의 하려고 하니 단어가 잘 생각이 안 났다.
  • 사실상 상속 개념을 처음으로 실습해서 부모 클래스에서 만든 메서드를 자주 잊어버렸다.

🔄 자체 평가 & 회고

  • 상속 활용 방법에 대한 공부가 필요 할 듯 하다.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

상속 과제 완료 - 코드 리뷰 및 학습 피드백

✅ 잘 구현된 부분

캡슐화 원칙 적용

  • Hero 클래스의 필드들(name, hp, maxHP)이 private으로 선언되어 직접 접근을 방지하고 있습니다.
  • setHp(), getHp()와 같은 접근자/변경자 메서드를 통해 제어되고 있습니다.

상속 관계 구현

  • GreatWizardWizard를 상속하여 "is-a" 관계를 표현했습니다.
  • super.heal()을 호출하여 부모의 기능을 확장하는 방식을 올바르게 사용했습니다.

메서드 오버라이딩

  • GreatWizard에서 heal() 메서드를 오버라이드하여 더 강력한 힐(부모의 힐 + 추가 효과)을 구현했습니다.

💭 함께 생각해볼 점들

1. 필드 접근 제어자 검토

  • Hero.getHp()가 현재 패키지 프라이빗(int getHp())입니다.
    • 🤔 질문: WizardGreatWizardhero.getHp()를 호출할 때 문제가 없나요? 만약 Wizard 클래스가 다른 패키지에 있다면 어떻게 될까요?
    • 💡 힌트: 부모-자식 클래스 간의 데이터 접근은 어떤 수준의 제어자가 적절할까요?

2. GreatWizard의 필드 정의 재검토

public class GreatWizard extends Wizard {
    int mp = 150;  // ← 이 부분이 의도적인가요?
  • 🤔 질문: GreatWizard에서 새로운 mp 필드를 선언한 이유가 무엇인가요? 부모 클래스 Wizard에도 이미 private int mp가 있는데...
  • 💡 힌트: 이것을 "필드 섀도윙(field shadowing)"이라고 합니다. 부모와 자식이 같은 이름의 필드를 가지면 어떤 문제가 생길 수 있을까요?
  • 제안: 부모 클래스의 필드를 그대로 상속받아 사용하는 것이 더 깔끔하지 않을까요?

3. Wizard.heal() 메서드의 논리

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());
}
  • 🤔 질문: 마나가 부족하다고 출력했는데, 정말로 힐이 시전되지 않나요?
  • 💡 힌트: 현재 코드는 마나 부족 메시지를 출력하고도 계속 진행됩니다. 이것이 의도한 동작인가요? 게임 로직상 "마나 부족 → 힐 시전 안 됨"이 더 맞지 않을까요?

🌟 다음 학습을 위한 제안

  1. 접근 제어자 복습: public, protected, 패키지 프라이빗의 차이를 다시 한번 정리하세요. 특히 상속 관계에서 각각 언제 사용해야 하는지 생각해보세요.

  2. return 문의 활용: 현재 Wizard.heal()처럼 조건에 따라 실행을 멈춰야 할 때, if 조건 { return; }을 사용하면 더 명확한 제어 흐름을 만들 수 있습니다.

  3. 부모 클래스 설계: 자식 클래스에서 필요한 데이터(예: hp, mp)를 부모가 제공해야 한다는 점을 기억하세요. 상속 관계에서는 재사용성이 핵심입니다!


📝 과제 요약

이 PR은 상속의 기본 개념을 실제 코드로 구현했다는 점에서 매우 좋은 시작입니다. 🎉

  • ✅ 모든 테스트 통과
  • ✅ 코드 포매팅 완료
  • GreatWizard라는 이름이 "Wizard의 한 종류"라는 관계를 잘 표현함

위의 피드백 포인트들을 정리하고 다시 한번 검토해보세요. 이러한 세부 사항들은 앞으로 더 복잡한 객체 지향 설계를 할 때 매우 중요한 기초가 될 것입니다! 화이팅! 💪

Walkthrough

Java 게임 프로젝트에서 Hero 필드를 캡슐화하고, Wizard의 heal 로직을 활성화하며, GreatWizard·Slime·PoisonSlime·SuperHero 신규 상속 클래스를 추가했다. Person 접근자 범위를 변경하고 관련 JUnit 5 테스트를 추가했으며, 기존 Main·Quiz·HeroTest 코드를 주석 처리하고 상속 학습 TIL 문서를 추가했다.

Changes

Java 게임 클래스 상속·캡슐화 구현

Layer / File(s) Summary
Hero 캡슐화 및 HP API 재구성
game/src/main/java/com/survivalcoding/Hero.java
name·hpprivate으로 변경하고 maxHP를 도입하며, maxHp()·heroRun()을 추가하고 setHp(int)public으로 변경한다. 기존 위치의 getHp() 선언은 제거된다.
Wizard heal 활성화 및 GreatWizard 상속 구현
game/src/main/java/com/survivalcoding/Wizard.java, game/src/main/java/com/survivalcoding/GreatWizard.java, game/src/game.puml, game/src/test/java/com/survivalcoding/WandTest.java
Wizardwizard(int mp) 초기화 메서드와 마나 체크·HP 증가 heal 로직을 추가하고, setMp 범위 검증을 제거하며 기존 getter/setter를 주석 처리한다. GreatWizardheal 오버라이드로 추가 증가, superHealhero.maxHp()를 호출한다. UML에 세 클래스 관계가 정의되고 WandTest로 HP 변화를 검증한다.
Slime·PoisonSlime·SuperHero 신규 상속 클래스
game/src/main/java/com/survivalcoding/Slime.java, game/src/main/java/com/survivalcoding/PoisonSlime.java, game/src/main/java/com/survivalcoding/SuperHero.java, game/src/test/java/com/survivalcoding/PoisonSlimeTest.java
Slime은 고정 -10 데미지 공격, PoisonSlimepoisonCount 카운트다운 후 독 데미지 추가 적용, SuperHeroisFlying 조건부 메시지 출력 후 super.attack() 호출로 구현된다. PoisonSlimeTest에서 10회 공격 후 HP 감소를 검증한다.
Person 접근자 변경 및 PersonTest 추가
game/src/main/java/com/survivalcoding/Person.java, game/src/test/java/com/survivalcoding/PersonTest.java
getName()·getAge()private에서 패키지 범위로 변경하고, 이름 문자열과 출력 포맷을 영어로 교체한다. PersonTest에서 두 getter의 반환값을 assertEquals로 검증한다.
Main·Quiz·HeroTest 기존 코드 주석 처리
game/src/main/java/com/survivalcoding/Main.java, game/src/main/java/com/survivalcoding/Quiz.java, game/src/test/java/com/survivalcoding/HeroTest.java
Main.main의 Hero/GreatWizard 초기화 및 heal 루프, Quiz.main의 Hero/Wizard 출력 블록 전체, HeroTestassertEquals 검증 구문이 주석 처리된다.

TIL 학습 문서 추가

Layer / File(s) Summary
TIL 상속 문서 및 캡슐화 문서 수정
TIL/sample/2026-06-15-캡슐-컬렉션.md, TIL/sample/2026-06-16-상속.md
캡슐화 문서의 '기억할 것' 헤딩이 수정된다. 상속 문서에 extends·오버라이드·super·is-a 개념 정리, Hero/SuperHero 생성자 예시, Wizard/GreatWizard 실습 코드, WandTest 시나리오, 회고 및 내일 주제가 추가된다.

추정 코드 리뷰 노력

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive 제목이 상속 개념 학습 과제를 다루는 변경사항을 명확하게 반영하지 못하고 있으며, 날짜와 학생명만 포함되어 있어 실제 변경 내용을 파악하기 어렵습니다. 상속 개념 학습 과제에 대한 구체적인 설명을 추가하거나 주요 변경사항(예: 'GreatWizard 상속 구현' 또는 '상속을 이용한 마법사 클래스 확장')을 포함하도록 제목을 개선해주세요.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed Pull request 설명이 제공된 템플릿의 모든 필수 섹션을 포함하고 있으며, 교육 주제(상속), 체크리스트 확인, 테스트 결과 이미지, 어려웠던 점, 자체 평가가 모두 작성되어 있습니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Nitpick comments (2)
game/src/main/java/com/survivalcoding/GreatWizard.java (1)

4-8: GreatWizard.mp 필드는 사용되지 않으므로 제거하세요.

자식 클래스의 int mp = 150; 필드는 초기화되지만 어떤 메서드에서도 실제로 사용되지 않습니다. heal()superHeal() 모두 부모의 getMp()setMp() 메서드를 통해서만 mp를 관리하므로, 이 필드는 혼동만 야기하는 불필요한 상태 복제입니다.

리팩터링 예시
 public class GreatWizard extends Wizard {
-    int mp = 150;
-
     public GreatWizard(int mp) {
         super.wizard(mp);
     }
🤖 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/GreatWizard.java` around lines 4 - 8,
The int mp field declaration in the GreatWizard class is unused and creates
unnecessary state duplication since both the heal() and superHeal() methods
manage mp exclusively through the parent class's getMp() and setMp() methods.
Remove the int mp = 150; field declaration from the GreatWizard class. The
constructor and all methods will continue to function correctly because they
rely on the parent class's mp state management.
game/src/test/java/com/survivalcoding/PoisonSlimeTest.java (1)

19-23: ⚡ Quick win

단언이 너무 느슨해서 독 공격 로직 회귀를 놓칠 수 있습니다.

현재 조건은 “기본 공격보다 조금 더 깎였는지”만 확인해서, 독 발동 타이밍/횟수 오류가 있어도 통과할 수 있습니다. 과제 스펙 기준 기대 HP(또는 구간별 변화량)를 명시적으로 검증하도록 단언을 강화해 주세요.

🤖 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/test/java/com/survivalcoding/PoisonSlimeTest.java` around lines 19 -
23, The assertion in the test for poisonSlimeAttack is too lenient and only
verifies that HP is reduced below a threshold rather than confirming the exact
expected damage from the poison attack mechanics. Replace the loose inequality
check in the assertTrue statement (comparing hero.getHp() < 1000 - (10 * 10))
with a strict equality assertion that validates the precise HP value expected
after 10 poison attacks according to the assignment specifications, such as
using assertEquals to confirm the exact final HP or the exact total damage
dealt.
🤖 Prompt for all review comments with 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.

Inline comments:
In `@game/src/game.puml`:
- Around line 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.

In `@game/src/main/java/com/survivalcoding/Person.java`:
- 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.

In `@game/src/main/java/com/survivalcoding/PoisonSlime.java`:
- Around line 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.

In `@game/src/main/java/com/survivalcoding/SuperHero.java`:
- Around line 13-18: The attack method in SuperHero class has a signature
mismatch with the parent Hero class. The method attack(int age) takes an age
parameter while the parent attack() method takes no parameters, preventing
proper method overriding and polymorphic behavior. Remove the int age parameter
from the SuperHero attack method signature to match the parent Hero.attack()
method exactly, and add the `@Override` annotation to ensure the compiler verifies
this is a proper override of the parent method.

In `@game/src/main/java/com/survivalcoding/Wizard.java`:
- Around line 16-22: The heal method in the Wizard class has a logic error where
insufficient mana is detected but the healing logic continues to execute anyway.
When mana is insufficient, add a return statement immediately after printing the
error message to prevent further execution of the method. Additionally, the mana
check condition should verify if there is enough mana to cast the spell (mp <
10, since the cost is 10), not just checking if mp is less than or equal to 0.
Fix the condition in the if statement and add the return statement so that when
mana is insufficient, the method exits without deducting mp or healing the hero.
- Around line 10-13: Convert the wizard(int mp) method in the Wizard class from
a regular method to an explicit constructor by renaming it to Wizard(int mp).
This enforces proper initialization when instances are created. In the
GreatWizard.java file, update the corresponding call from super.wizard(mp) to
super(mp) to invoke the parent constructor instead of the parent method.

In `@game/src/test/java/com/survivalcoding/HeroTest.java`:
- Around line 16-26: The test method in HeroTest is currently ineffective
because all the assertEquals assertions that verify the hero's HP after calling
attack() are commented out. Uncomment the assertion statements (the assertEquals
calls that check hero.hp against expected values) to restore the test validation
logic. At minimum, uncomment the final assertEquals after the third attack()
call to verify the hero's HP has decreased correctly, so the test can actually
catch failures in the attack() method behavior.

---

Nitpick comments:
In `@game/src/main/java/com/survivalcoding/GreatWizard.java`:
- Around line 4-8: The int mp field declaration in the GreatWizard class is
unused and creates unnecessary state duplication since both the heal() and
superHeal() methods manage mp exclusively through the parent class's getMp() and
setMp() methods. Remove the int mp = 150; field declaration from the GreatWizard
class. The constructor and all methods will continue to function correctly
because they rely on the parent class's mp state management.

In `@game/src/test/java/com/survivalcoding/PoisonSlimeTest.java`:
- Around line 19-23: The assertion in the test for poisonSlimeAttack is too
lenient and only verifies that HP is reduced below a threshold rather than
confirming the exact expected damage from the poison attack mechanics. Replace
the loose inequality check in the assertTrue statement (comparing hero.getHp() <
1000 - (10 * 10)) with a strict equality assertion that validates the precise HP
value expected after 10 poison attacks according to the assignment
specifications, such as using assertEquals to confirm the exact final HP or the
exact total damage dealt.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 16ccf064-26c0-42a5-9e8b-e3becb790b09

📥 Commits

Reviewing files that changed from the base of the PR and between 4f62c5f and b2849b5.

📒 Files selected for processing (16)
  • TIL/sample/2026-06-15-캡슐-컬렉션.md
  • TIL/sample/2026-06-16-상속.md
  • game/src/game.puml
  • game/src/main/java/com/survivalcoding/GreatWizard.java
  • game/src/main/java/com/survivalcoding/Hero.java
  • game/src/main/java/com/survivalcoding/Main.java
  • game/src/main/java/com/survivalcoding/Person.java
  • game/src/main/java/com/survivalcoding/PoisonSlime.java
  • game/src/main/java/com/survivalcoding/Quiz.java
  • game/src/main/java/com/survivalcoding/Slime.java
  • game/src/main/java/com/survivalcoding/SuperHero.java
  • game/src/main/java/com/survivalcoding/Wizard.java
  • game/src/test/java/com/survivalcoding/HeroTest.java
  • game/src/test/java/com/survivalcoding/PersonTest.java
  • game/src/test/java/com/survivalcoding/PoisonSlimeTest.java
  • game/src/test/java/com/survivalcoding/WandTest.java

Comment thread game/src/game.puml
Comment on lines +20 to +26
+ wizard(mp: int)
+ heal(hero: Hero)
+ setMp(mp: int)
+ getMp(): int
+ getHp(): int
+ setHp(hp: int)
}

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.


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.

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

}
poisonCount--;

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.

Comment on lines +13 to +18
public void attack(int age) {
if (isFlying) {
System.out.println("한번더");
}
super.attack();
}

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

Hero.attack()를 재정의하지 못해 다형성 경로에서 동작이 누락됩니다.

Line 13의 attack(int age)는 부모 attack()을 오버라이드하지 않으므로, Hero 타입 참조로 호출 시 SuperHero 쪽 비행 분기 로직이 적용되지 않습니다. 시그니처를 부모와 맞추고 @Override를 추가하세요.

수정 예시
-    public void attack(int age) {
+    `@Override`
+    public void attack() {
         if (isFlying) {
             System.out.println("한번더");
         }
         super.attack();
     }
📝 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
public void attack(int age) {
if (isFlying) {
System.out.println("한번더");
}
super.attack();
}
`@Override`
public void attack() {
if (isFlying) {
System.out.println("한번더");
}
super.attack();
}
🤖 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/SuperHero.java` around lines 13 - 18,
The attack method in SuperHero class has a signature mismatch with the parent
Hero class. The method attack(int age) takes an age parameter while the parent
attack() method takes no parameters, preventing proper method overriding and
polymorphic behavior. Remove the int age parameter from the SuperHero attack
method signature to match the parent Hero.attack() method exactly, and add the
`@Override` annotation to ensure the compiler verifies this is a proper override
of the parent method.

Comment on lines +10 to +13
public void wizard(int mp) {
//if (this.mp < mp) {
this.mp = mp;
//}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 목적: 생성자 전환 시 영향 범위 확인 (읽기 전용)
rg -nP --type=java -C2 '\bnew\s+Wizard\s*\('
rg -nP --type=java -C2 '\bwizard\s*\('

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 806


🏁 Script executed:

# Inspect Wizard.java fully
cat -n game/src/main/java/com/survivalcoding/Wizard.java

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 2520


🏁 Script executed:

# Inspect GreatWizard.java fully  
cat -n game/src/main/java/com/survivalcoding/GreatWizard.java

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 702


🏁 Script executed:

# Search for all calls to wizard() method to ensure no other callers
rg -nP --type=java '\bwizard\s*\(' -B1 -A1

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 540


🏁 Script executed:

# Search for all Wizard instantiations to check if default constructor is used
rg -nP --type=java '\bWizard\s*\(' --glob='!Wizard.java' -B2 -A2

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 61


wizard(int mp) 메서드를 생성자로 전환하세요.

현재 wizard(int mp) 메서드는 생성자의 역할을 하지만 일반 메서드로 정의되어 있습니다. Wizard 클래스에 명시적 생성자가 없어서 new Wizard() 호출 시 초기화 누락이 발생할 수 있습니다. Wizard(int mp) 생성자로 변환하면 초기화를 강제하며 코드의 의도가 더 명확해집니다.

영향 범위는 GreatWizard.java 라인 7의 super.wizard(mp); 호출만 변경하면 됩니다.

리팩터링 예시
 public class Wizard {
-    public void wizard(int mp) {
+    public Wizard(int mp) {
         this.mp = mp;
     }
 public class GreatWizard extends Wizard {
     public GreatWizard(int mp) {
-        super.wizard(mp);
+        super(mp);
     }
 }
🤖 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/Wizard.java` around lines 10 - 13,
Convert the wizard(int mp) method in the Wizard class from a regular method to
an explicit constructor by renaming it to Wizard(int mp). This enforces proper
initialization when instances are created. In the GreatWizard.java file, update
the corresponding call from super.wizard(mp) to super(mp) to invoke the parent
constructor instead of the parent method.

Comment on lines +16 to +22
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());

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

마나 부족 분기에서 힐을 계속 진행하는 로직 오류가 있습니다.

현재는 마나가 부족해도 MP를 추가 차감하고 대상 HP를 회복시킵니다. 시전 비용(10) 미만이면 즉시 종료해야 합니다.

수정 예시
 public void heal(Hero hero) {
-    if (this.mp <= 0) {
+    if (this.mp < 10) {
         System.out.println("마나가 부족합니다.");
+        return;
     }
     this.mp -= 10;
     hero.setHp(hero.getHp() + 20);
     System.out.println("힐을 시전 하였습니다. 대상 HP: " + hero.getHp());
 }
📝 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
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 heal(Hero hero) {
if (this.mp < 10) {
System.out.println("마나가 부족합니다.");
return;
}
this.mp -= 10;
hero.setHp(hero.getHp() + 20);
System.out.println("힐을 시전 하였습니다. 대상 HP: " + hero.getHp());
}
🤖 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/Wizard.java` around lines 16 - 22, The
heal method in the Wizard class has a logic error where insufficient mana is
detected but the healing logic continues to execute anyway. When mana is
insufficient, add a return statement immediately after printing the error
message to prevent further execution of the method. Additionally, the mana check
condition should verify if there is enough mana to cast the spell (mp < 10,
since the cost is 10), not just checking if mp is less than or equal to 0. Fix
the condition in the if statement and add the return statement so that when mana
is insufficient, the method exits without deducting mp or healing the hero.

Comment on lines +16 to +26
//hero.hp = 10;
hero.attack(); //9
hero.attack(); //8

// then (검증)
assertEquals(9, hero.hp); // 9
//assertEquals(9, hero.hp); // 9

hero.attack(); // 8

// then (검증)
assertEquals(8, hero.hp); // 8
//assertEquals(8, hero.hp); // 8

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

검증식이 주석 처리되어 테스트가 사실상 무효입니다.

현재 attack() 테스트는 실패 조건을 잡지 못합니다. 최소한 최종 HP 검증을 복구해야 합니다.

수정 예시
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
@@
     void attack() {
@@
-        //hero.hp = 10;
         hero.attack(); //9
         hero.attack(); //8
-
-        //assertEquals(9, hero.hp);    // 9
-
         hero.attack();  // 8
-
-        //assertEquals(8, hero.hp);    // 8
+        assertEquals(97, hero.getHp());
     }
🤖 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/test/java/com/survivalcoding/HeroTest.java` around lines 16 - 26,
The test method in HeroTest is currently ineffective because all the
assertEquals assertions that verify the hero's HP after calling attack() are
commented out. Uncomment the assertion statements (the assertEquals calls that
check hero.hp against expected values) to restore the test validation logic. At
minimum, uncomment the final assertEquals after the third attack() call to
verify the hero's HP has decreased correctly, so the test can actually catch
failures in the attack() method behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant