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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.survivalcoding;

public class GreatWizard extends Wizard {
public GreatWizard() {
setMp(150);
}

@Override
public void heal(Hero hero) {
if (getMp() < 5) {
System.out.println("마나가 부족합니다");
return;
}
hero.setHp(hero.getHp() + 25);
setMp(getMp() - 5);
System.out.println("힐을 시전했습니다. 대상 HP: " + hero.getHp());
}

public void superHeal(Hero hero) {
if (getMp() < 50) {
System.out.println("마나가 부족합니다");
return;
}

hero.setHp(100);
setMp(getMp() - 50);
System.out.println("슈퍼 힐을 시전했습니다. 대상 HP: " + hero.getHp());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.survivalcoding;

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

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

@Override
void attack(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--;
}
}
}
21 changes: 21 additions & 0 deletions day02-instance-class/src/main/java/com/survivalcoding/Slime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.survivalcoding;

public class Slime {

final String suffix;
int hp;

public Slime(String suffix) {
this.suffix = suffix;
this.hp = 50;
}

// 생성자, getter, setter 작성

void attack(Hero hero) {
System.out.println("슬라임 " + suffix + "이/가 공격했다");
System.out.println("10의 데미지");

hero.setHp(hero.getHp() - 10);
}
}
65 changes: 65 additions & 0 deletions day02-instance-class/src/main/java/com/survivalcoding/Wizard.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,69 @@
package com.survivalcoding;

public class Wizard {

private int hp;
private int mp = 100;
private String name;
private Wand wand;

public int getHp() {
return hp;
}

public void setHp(int hp) {
if (hp < 0) {
this.hp = 0;
return;
}
this.hp = hp;
}

public int getMp() {
return mp;
}

public String getName() {
return name;
}

public void setName(String name) {
if (name == null || name.length() < 3) {
throw new IllegalArgumentException("마법사의 이름은 null일 수 없고 3문자 이상이어야 합니다");
}
this.name = name;
}

public void setMp(int mp) {
if (mp < 0) {
throw new IllegalArgumentException("마법사의 MP는 0 이상이어야 합니다");
}
this.mp = mp;
}

public void setWand(Wand wand) {
if (wand == null) {
throw new IllegalArgumentException("마법사의 지팡이는 null일수 없습니다.");
}
this.wand = wand;
}

public void heal(Hero hero) {
if (mp < 10) {
System.out.println("마나가 부족합니다");
return;
}

hero.setHp(hero.getHp() + 20);
mp -= 10;
System.out.println("힐을 시전했습니다. 대상 HP: " + hero.getHp());
}
Comment on lines +51 to +60

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

공통 원인: 전투/치유 API의 대상 파라미터 null 경계 검증이 빠져 있습니다.

  • day02-instance-class/src/main/java/com/survivalcoding/Wizard.java#L51-L60: heal(Hero hero) 시작 지점에 null 검증을 추가하세요.
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java#L9-L17: heal(Hero hero)에 동일한 null 검증(또는 공통 헬퍼)을 적용하세요.
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java#L19-L27: superHeal(Hero hero)에도 동일한 검증을 적용하세요.
  • day02-instance-class/src/main/java/com/survivalcoding/Slime.java#L15-L20: attack(Hero hero) 베이스 메서드에서 null 검증을 추가해 하위 클래스 호출 경로까지 보호하세요.
📍 Affects 3 files
  • day02-instance-class/src/main/java/com/survivalcoding/Wizard.java#L51-L60 (this comment)
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java#L9-L17
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java#L19-L27
  • day02-instance-class/src/main/java/com/survivalcoding/Slime.java#L15-L20
🤖 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 `@day02-instance-class/src/main/java/com/survivalcoding/Wizard.java` around
lines 51 - 60, Add null validation for the hero parameter at the beginning of
each method to prevent NullPointerException. In
day02-instance-class/src/main/java/com/survivalcoding/Wizard.java lines 51-60,
add a null check for the hero parameter at the start of the heal method before
any logic executes. Apply the same null validation pattern to
day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java lines
9-17 in the heal method override and lines 19-27 in the superHeal method.
Additionally, add null validation in
day02-instance-class/src/main/java/com/survivalcoding/Slime.java lines 15-20 at
the start of the attack method to protect the base method that is called by
subclasses. Each null check should return early or print an appropriate error
message if the hero parameter is null.



public void fireball(Hero hero) {


}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.survivalcoding;

public class 연습문제_1 {
/* 1. Person Student (O)
2. car Engine (X)
3. Father Child (X)
4. Food Sushi (O)
5. SuperMan Man (X)



*/
}


/* 연습문제_2
1 2 3
부모 클래스 ElectronicDevice Vehicle Book


Phone Car Dictionary



자식 클래스 I-Phone Bus EnglishDictionary


*/