260616_09_박성연#63
Conversation
상속 실습 코드 리뷰 피드백좋은 점 ✅
개선이 필요한 부분 🤔1. Slime 클래스의 생성자 문제public Slime(String suffix, int hp) {
} // 비어있습니다질문: 생성자 본문이 비어 있는데, 전달받은 2. 필드 초기화 누락
3. GreatWizard의 필드 중복 문제public class GreatWizard extends Wizard{
private int mp = 150; // 부모 클래스에도 이미 있습니다
// ...
}개념: 부모 클래스인 질문:
4. 존재하지 않는 상수 참조void superHeal(Hero hero) {
// ...
hero.setHp(Max_Hp); // Max_Hp는 어디에 정의되어 있나요?
}힌트: 5. Hero 클래스의 메서드 누락
6. 메서드 오버라이드 고려사항
캡슐화와 접근 제한자 확인
정리하며 🎯이번 과제를 통해:
을 깊이 있게 이해하는 것이 목표입니다. 위의 질문들을 스스로 생각해보고 수정해보세요! Walkthrough게임 패키지에 Changes게임 상속 계층 구현
TIL 상속 문서
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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 Warning |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
TIL/sample/2026-06-16-상속.md (1)
18-22: ⚡ Quick win실습 코드 블록에 예제를 채워 주세요.
현재 코드 블록이 비어 있어서
extends/super를 실제로 어떻게 쓰는지 문서에서 바로 확인할 수 없습니다.🧩 예시 추가안
## 실습 코드 ```java +class Parent { + void hello() {} +} + +class Child extends Parent { + `@Override` + void hello() { + super.hello(); + } +}</details> <details> <summary>🤖 Prompt for AI Agents</summary>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-상속.mdaround lines 18 - 22, The practice code section
in the "실습 코드" block is empty and needs to include a concrete Java example
demonstrating inheritance concepts. Add a Parent class with a hello() method,
then create a Child class that extends Parent using the extends keyword and
overrides the hello() method with the@Overrideannotation, calling the parent
class's hello() method using super.hello(). This will provide readers with a
clear, working example of how extends and super keywords are used in Java
inheritance.</details> <!-- cr-comment:v1:31b4ea2aef10ec33936e3ea9 --> </blockquote></details> </blockquote></details> <details> <summary>🤖 Prompt for all review comments with AI agents</summary>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/game.puml:
- Around line 5-6: Update the PlantUML diagram signatures for the methods
setFlying and isFlying to match the actual code implementation. Change the
access modifier from + (public) to match the package-private visibility of the
actual methods in the code. Additionally, correct the type declarations from
bool to boolean to match the Java type conventions used in the actual
implementation. Apply these same corrections to all other occurrences mentioned
at lines 17, 21, 25, and 29 to ensure the entire diagram is consistent with the
current codebase.In
@game/src/main/java/com/survivalcoding/GreatWizard.java:
- Line 15: The identifier
Max_Hpon line 15 in the GreatWizard.java file is
undefined and does not follow Java naming conventions for constants. Replace
Max_HpwithHero.MAX_HPwhen calling thehero.setHp()method, as MAX_HP is
defined as a static final constant in the Hero class with proper uppercase
naming convention.- Around line 4-17: The GreatWizard class has an MP management issue caused by
field shadowing and incorrect target selection. Remove the shadowing mp field
declaration at line 4, and fix both the heal and superHeal methods to deduct MP
from the GreatWizard caster (using this context or inherited mp from parent
Wizard) instead of from the target hero parameter. This applies to both the
setMp call in the heal method and the setMp call in the superHeal method,
ensuring consistent MP cost accounting for the spell caster's own resource
usage.In
@game/src/main/java/com/survivalcoding/Slime.java:
- Around line 7-11: The Slime(String suffix, int hp) constructor at line 7 is
empty and fails to initialize the required fields. Inside this constructor body,
add statements to initialize the suffix field with the suffix parameter and
assign the hp parameter to the corresponding hp field, following the same
pattern as shown in the Slime(String suffix) constructor which properly assigns
this.suffix = suffix.In
@game/src/main/java/com/survivalcoding/Wizard.java:
- Around line 62-67: The heal() method in the Wizard class is incorrectly
consuming the target hero's MP instead of the caster's MP. In the heal() method,
the line that calls hero.setMp(hero.getMp() - usedPoint) is decrementing the
target's MP, but it should instead decrement the Wizard's own MP (the caster).
Change the MP deduction to use the Wizard instance's MP property instead of the
hero parameter's MP property to correctly represent resource consumption by the
spell caster.In
@TIL/sample/2026-06-16-상속.md:
- Around line 6-10: Correct the terminology and spelling errors in the
inheritance document to improve credibility. Replace "override vs 클래스 overload"
with proper Korean terminology for "메서드 재정의(override)" and "메서드 오버로딩(overload)".
Fix the typos: change "클리스" to "클래스", "extands" to "extends", and "매소드" to "메서드"
throughout the document. These corrections will ensure the technical terms are
accurate and the document is free of spelling errors that undermine its
trustworthiness.
Nitpick comments:
In@TIL/sample/2026-06-16-상속.md:
- Around line 18-22: The practice code section in the "실습 코드" block is empty and
needs to include a concrete Java example demonstrating inheritance concepts. Add
a Parent class with a hello() method, then create a Child class that extends
Parent using the extends keyword and overrides the hello() method with the
@Overrideannotation, calling the parent class's hello() method using
super.hello(). This will provide readers with a clear, working example of how
extends and super keywords are used in Java inheritance.</details> <details> <summary>🪄 Autofix (Beta)</summary> Fix all unresolved CodeRabbit comments on this PR: - [ ] <!-- {"checkboxId": "4b0d0e0a-96d7-4f10-b296-3a18ea78f0b9"} --> Push a commit to this branch (recommended) - [ ] <!-- {"checkboxId": "ff5b1114-7d8c-49e6-8ac1-43f82af23a33"} --> Create a new PR with the fixes </details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Organization UI **Review profile**: CHILL **Plan**: Pro **Run ID**: `930c467a-9d7f-49ad-80cd-58687f5156ad` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between db04b9e7e75e871ed860da8d5439b3220592a76c and 109c8a2242880d72c9e650c6156579eebf0a2bac. </details> <details> <summary>📒 Files selected for processing (6)</summary> * `TIL/sample/2026-06-16-상속.md` * `game/game.puml` * `game/src/main/java/com/survivalcoding/GreatWizard.java` * `game/src/main/java/com/survivalcoding/PoisonSlime.java` * `game/src/main/java/com/survivalcoding/Slime.java` * `game/src/main/java/com/survivalcoding/Wizard.java` </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
| +void setFlying(bool flying) | ||
| +boolean isFlying() |
There was a problem hiding this comment.
PlantUML 시그니처가 실제 코드와 불일치합니다.
접근제어자(+ vs package-private)와 타입(bool)이 코드와 맞지 않아 다이어그램 신뢰도가 떨어집니다. 현재 코드 기준으로 동기화해 주세요.
🔧 제안 수정안
class SuperHero extends Hero {
- +void setFlying(bool flying)
+ +void setFlying(boolean flying)
+boolean isFlying()
}
class Wizard {
- +void heal(Hero)
+ ~void heal(Hero)
}
class GreatWizard extends Wizard {
- +void superHeal(Hero)
+ ~void superHeal(Hero)
}
class Slime {
- +void attack(Hero)
+ ~void attack(Hero)
}
class PoisonSlime extends Slime {
- +void attack(Hero) <<`@Override`>>
+ ~void attack(Hero) <<`@Override`>>
}Also applies to: 17-17, 21-21, 25-25, 29-29
🤖 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` around lines 5 - 6, Update the PlantUML diagram signatures
for the methods setFlying and isFlying to match the actual code implementation.
Change the access modifier from + (public) to match the package-private
visibility of the actual methods in the code. Additionally, correct the type
declarations from bool to boolean to match the Java type conventions used in the
actual implementation. Apply these same corrections to all other occurrences
mentioned at lines 17, 21, 25, and 29 to ensure the entire diagram is consistent
with the current codebase.
| private int mp = 150; | ||
| void heal (Hero hero) { | ||
| hero.setHp(hero.getHp() +25); | ||
| hero.setMp(hero.getMp() -5); | ||
|
|
||
| } | ||
| void superHeal (Hero hero) { | ||
| if (hero.getMp() < 50) { | ||
| System.out.println("마나가 부족합니다."); | ||
| } | ||
| else{ | ||
| hero.setHp(Max_Hp); | ||
| hero.setMp(hero.getMp() -50); | ||
| System.out.println("슈퍼 힐을 시전했습니다. 대상 HP: " + hero.getHp()); |
There was a problem hiding this comment.
GreatWizard의 MP 상태 모델이 깨져 있습니다(필드 섀도잉 + 대상 MP 차감).
Line 4에서 부모 Wizard.mp를 섀도잉하고, Line 7/16에서는 시전자 MP가 아니라 대상 hero MP를 차감하고 있습니다. 결과적으로 GreatWizard 자신의 MP 관리가 일관되지 않습니다.
🔧 제안 수정안
public class GreatWizard extends Wizard{
- private int mp = 150;
+ public GreatWizard() {
+ this.setMp(150);
+ }
void heal (Hero hero) {
+ if (this.getMp() < 5) {
+ throw new IllegalStateException("마나가 부족합니다.");
+ }
hero.setHp(hero.getHp() +25);
- hero.setMp(hero.getMp() -5);
+ this.setMp(this.getMp() -5);
}
void superHeal (Hero hero) {
- if (hero.getMp() < 50) {
+ if (this.getMp() < 50) {
System.out.println("마나가 부족합니다.");
}
else{
hero.setHp(Max_Hp);
- hero.setMp(hero.getMp() -50);
+ this.setMp(this.getMp() -50);
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/GreatWizard.java` around lines 4 - 17,
The GreatWizard class has an MP management issue caused by field shadowing and
incorrect target selection. Remove the shadowing mp field declaration at line 4,
and fix both the heal and superHeal methods to deduct MP from the GreatWizard
caster (using this context or inherited mp from parent Wizard) instead of from
the target hero parameter. This applies to both the setMp call in the heal
method and the setMp call in the superHeal method, ensuring consistent MP cost
accounting for the spell caster's own resource usage.
| System.out.println("마나가 부족합니다."); | ||
| } | ||
| else{ | ||
| hero.setHp(Max_Hp); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Read-only verification: locate hp max constants and references
rg -n -C2 '\bMax_Hp\b|\bMAX_HP\b|\bmaxHp\b'
fd -i 'Hero.java' | xargs -I{} sed -n '1,220p' {}
fd -i 'Wizard.java' | xargs -I{} sed -n '1,220p' {}Repository: SurvivalCodingCampus/polytech_java2
Length of output: 5060
Max_Hp는 정의되지 않은 식별자입니다. Hero.MAX_HP를 사용해주세요.
Line 15의 Max_Hp는 현재 파일 범위에서나 상속 계층에서도 선언되지 않았습니다. Hero 클래스에서 정의된 static final int MAX_HP = 50을 참조해야 하므로 Hero.MAX_HP로 변경하세요. 또한 Java 명명 규칙에 따라 상수는 MAX_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/main/java/com/survivalcoding/GreatWizard.java` at line 15, The
identifier `Max_Hp` on line 15 in the GreatWizard.java file is undefined and
does not follow Java naming conventions for constants. Replace `Max_Hp` with
`Hero.MAX_HP` when calling the `hero.setHp()` method, as MAX_HP is defined as a
static final constant in the Hero class with proper uppercase naming convention.
| public Slime(String suffix, int hp) { | ||
| } | ||
| public Slime(String suffix) { | ||
| this.suffix = suffix; | ||
| } |
There was a problem hiding this comment.
Slime(String suffix, int hp) 생성자에서 필수 필드 초기화가 누락되었습니다.
Line 7의 생성자가 비어 있어서 final 필드 suffix가 초기화되지 않고, hp도 반영되지 않습니다. 현재 상태로는 컴파일 실패 가능성이 큽니다.
🔧 제안 수정안
public class Slime {
final String suffix;
int hp;
public Slime(String suffix, int hp) {
+ this.suffix = suffix;
+ this.hp = hp;
}
public Slime(String suffix) {
- this.suffix = suffix;
+ this(suffix, 100);
}📝 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 Slime(String suffix, int hp) { | |
| } | |
| public Slime(String suffix) { | |
| this.suffix = suffix; | |
| } | |
| public class Slime { | |
| final String suffix; | |
| int hp; | |
| public Slime(String suffix, int hp) { | |
| this.suffix = suffix; | |
| this.hp = hp; | |
| } | |
| public Slime(String suffix) { | |
| this(suffix, 100); | |
| } | |
| } |
🤖 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/Slime.java` around lines 7 - 11, The
Slime(String suffix, int hp) constructor at line 7 is empty and fails to
initialize the required fields. Inside this constructor body, add statements to
initialize the suffix field with the suffix parameter and assign the hp
parameter to the corresponding hp field, following the same pattern as shown in
the Slime(String suffix) constructor which properly assigns this.suffix =
suffix.
| void heal(Hero hero) { | ||
| int basePoint = 10; | ||
| int recovPoint = (int) (basePoint * this.wand.power); | ||
| hero.setHp(hero.getHp() + recovPoint); | ||
| int recoverPoint = 20; | ||
| int usedPoint = 10; | ||
|
|
||
| hero.setHp(hero.getHp() + recoverPoint); | ||
| hero.setMp(hero.getMp() - usedPoint); |
There was a problem hiding this comment.
heal()이 시전자 MP가 아니라 대상 MP를 차감하고 있습니다.
Line 67에서 hero.setMp(...)를 호출해 대상의 MP를 소모하고 있어, Wizard.mp 상태가 전혀 사용되지 않습니다. 시전자 자원 소모로 수정하는 게 맞습니다.
🔧 제안 수정안
void heal(Hero hero) {
int recoverPoint = 20;
int usedPoint = 10;
+ if (this.mp < usedPoint) {
+ throw new IllegalStateException("마나가 부족합니다.");
+ }
hero.setHp(hero.getHp() + recoverPoint);
- hero.setMp(hero.getMp() - usedPoint);
+ this.setMp(this.mp - usedPoint);
}🤖 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 62 - 67, The
heal() method in the Wizard class is incorrectly consuming the target hero's MP
instead of the caster's MP. In the heal() method, the line that calls
hero.setMp(hero.getMp() - usedPoint) is decrementing the target's MP, but it
should instead decrement the Wizard's own MP (the caster). Change the MP
deduction to use the Wizard instance's MP property instead of the hero
parameter's MP property to correctly represent resource consumption by the spell
caster.
| - 메소드 override vs 클래스 overload | ||
| - String 클리스 상속 못함, final 붙이면 상속 못함. | ||
| - | ||
| - (왜) 복사붙여넣기의 문제점 (추가, 수정에 시간이 걸림. 소스의 파악이나 관리가 어려워짐.) | ||
| - (어떻게) 클래스 상속 키워드: extands, 매소드 상속 키워드: super |
There was a problem hiding this comment.
용어와 오탈자를 바로잡아 주세요.
override/overload는 각각 메서드 재정의 / 메서드 오버로딩을 뜻합니다. 또한 클리스, extands, 매소드는 오탈자라 문서 신뢰도가 떨어집니다.
🛠️ پیشن수정 예시
-- 메소드 override vs 클래스 overload
-- String 클리스 상속 못함, final 붙이면 상속 못함.
-- (어떻게) 클래스 상속 키워드: extands, 매소드 상속 키워드: super
+- 메서드 override vs 메서드 overload
+- String 클래스는 상속할 수 없음. `final`이 붙은 클래스도 상속할 수 없음.
+- (어떻게) 클래스 상속 키워드: extends, 메서드 상속 키워드: super🤖 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 6 - 10, Correct the terminology and
spelling errors in the inheritance document to improve credibility. Replace
"override vs 클래스 overload" with proper Korean terminology for "메서드
재정의(override)" and "메서드 오버로딩(overload)". Fix the typos: change "클리스" to "클래스",
"extands" to "extends", and "매소드" to "메서드" throughout the document. These
corrections will ensure the technical terms are accurate and the document is
free of spelling errors that undermine its trustworthiness.
260616_09_박성연
📝 과제 정보
📋 체크리스트
📷 실행 결과 (또는 테스트 결과)
❓질문 및 어려웠던 점
🔄 자체 평가 & 회고