260616_18_서수현#58
Conversation
상속 과제 완료 - 코드 리뷰 및 학습 피드백✅ 잘 구현된 부분캡슐화 원칙 적용
상속 관계 구현
메서드 오버라이딩
💭 함께 생각해볼 점들1. 필드 접근 제어자 검토
2. GreatWizard의 필드 정의 재검토 public class GreatWizard extends Wizard {
int mp = 150; // ← 이 부분이 의도적인가요?
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());
}
🌟 다음 학습을 위한 제안
📝 과제 요약이 PR은 상속의 기본 개념을 실제 코드로 구현했다는 점에서 매우 좋은 시작입니다. 🎉
위의 피드백 포인트들을 정리하고 다시 한번 검토해보세요. 이러한 세부 사항들은 앞으로 더 복잡한 객체 지향 설계를 할 때 매우 중요한 기초가 될 것입니다! 화이팅! 💪 WalkthroughJava 게임 프로젝트에서 ChangesJava 게임 클래스 상속·캡슐화 구현
TIL 학습 문서 추가
추정 코드 리뷰 노력🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (16)
TIL/sample/2026-06-15-캡슐-컬렉션.mdTIL/sample/2026-06-16-상속.mdgame/src/game.pumlgame/src/main/java/com/survivalcoding/GreatWizard.javagame/src/main/java/com/survivalcoding/Hero.javagame/src/main/java/com/survivalcoding/Main.javagame/src/main/java/com/survivalcoding/Person.javagame/src/main/java/com/survivalcoding/PoisonSlime.javagame/src/main/java/com/survivalcoding/Quiz.javagame/src/main/java/com/survivalcoding/Slime.javagame/src/main/java/com/survivalcoding/SuperHero.javagame/src/main/java/com/survivalcoding/Wizard.javagame/src/test/java/com/survivalcoding/HeroTest.javagame/src/test/java/com/survivalcoding/PersonTest.javagame/src/test/java/com/survivalcoding/PoisonSlimeTest.javagame/src/test/java/com/survivalcoding/WandTest.java
| + wizard(mp: int) | ||
| + heal(hero: Hero) | ||
| + setMp(mp: int) | ||
| + getMp(): int | ||
| + getHp(): int | ||
| + setHp(hp: int) | ||
| } |
There was a problem hiding this comment.
UML 공개 API가 현재 코드와 불일치합니다.
Wizard의 getHp()/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"); |
There was a problem hiding this comment.
출력 문자열 공백 누락 수정 필요
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.
| 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.
| if (poisonCount <= 0) { | ||
| System.out.println("독포자를 살포 했다!"); | ||
| int poisonDamage = hero.getHp() / 5; | ||
| hero.setHp(hero.getHp() - poisonDamage); | ||
| System.out.println(poisonDamage + " 포인트 데미지"); | ||
|
|
||
| } | ||
| poisonCount--; |
There was a problem hiding this comment.
독 공격 발동 조건이 반대로 되어 있어 사용 횟수 제한이 깨집니다.
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.
| 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.
| public void attack(int age) { | ||
| if (isFlying) { | ||
| System.out.println("한번더"); | ||
| } | ||
| super.attack(); | ||
| } |
There was a problem hiding this comment.
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.
| 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.
| public void wizard(int mp) { | ||
| //if (this.mp < mp) { | ||
| this.mp = mp; | ||
| //} |
There was a problem hiding this comment.
🛠️ 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.javaRepository: SurvivalCodingCampus/polytech_java2
Length of output: 2520
🏁 Script executed:
# Inspect GreatWizard.java fully
cat -n game/src/main/java/com/survivalcoding/GreatWizard.javaRepository: 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 -A1Repository: 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 -A2Repository: 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.
| 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()); |
There was a problem hiding this comment.
마나 부족 분기에서 힐을 계속 진행하는 로직 오류가 있습니다.
현재는 마나가 부족해도 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.
| 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.
| //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 |
There was a problem hiding this comment.
검증식이 주석 처리되어 테스트가 사실상 무효입니다.
현재 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.
260616_18_서수현
📝 과제 정보
📋 체크리스트
📷 실행 결과 (또는 테스트 결과)
❓질문 및 어려웠던 점
🔄 자체 평가 & 회고