-
Notifications
You must be signed in to change notification settings - Fork 18
260616_09_박성연 #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: student/09_박성연
Are you sure you want to change the base?
260616_09_박성연 #63
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # 2026-06-16 상속 | ||
|
|
||
| ## 오늘 배운 내용 | ||
|
|
||
| - 상속: 클래스의 확장 | ||
| - 메소드 override vs 클래스 overload | ||
| - String 클리스 상속 못함, final 붙이면 상속 못함. | ||
| - | ||
| - (왜) 복사붙여넣기의 문제점 (추가, 수정에 시간이 걸림. 소스의 파악이나 관리가 어려워짐.) | ||
| - (어떻게) 클래스 상속 키워드: extands, 매소드 상속 키워드: super | ||
| - (언제) 자식 is a 부모 조건 성립시 e.g. 스마트폰 is a 전자기기 | ||
| - (어디서)새로운 자식 클래스에서 | ||
| - (무엇을)부모 클래스를 | ||
| - (누가) JAVA | ||
|
|
||
|
|
||
|
|
||
| ## 실습 코드 | ||
|
|
||
| ```java | ||
|
|
||
| ``` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| @startuml | ||
| scale 2 | ||
|
|
||
| class SuperHero extends Hero { | ||
| +void setFlying(bool flying) | ||
| +boolean isFlying() | ||
|
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PlantUML 시그니처가 실제 코드와 불일치합니다. 접근제어자( 🔧 제안 수정안 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 |
||
| } | ||
|
|
||
| class Hero { | ||
| -int hp //private | ||
| -String name | ||
|
|
||
| +void attack() | ||
| } | ||
|
|
||
| class Wizard { | ||
| +void heal(Hero) | ||
| } | ||
|
|
||
| class GreatWizard extends Wizard { | ||
| +void superHeal(Hero) | ||
| } | ||
|
|
||
| class Slime { | ||
| +void attack(Hero) | ||
| } | ||
|
|
||
| class PoisonSlime extends Slime { | ||
| +void attack(Hero) <<@Override>> | ||
| } | ||
| @enduml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class GreatWizard extends Wizard{ | ||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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
Line 15의 🤖 Prompt for AI Agents |
||
| hero.setMp(hero.getMp() -50); | ||
| System.out.println("슈퍼 힐을 시전했습니다. 대상 HP: " + hero.getHp()); | ||
|
Comment on lines
+4
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 4에서 부모 🔧 제안 수정안 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 |
||
| } | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class PoisonSlime extends Slime{ | ||
| private int poisonCount = 5; | ||
|
|
||
|
|
||
| public PoisonSlime(String suffix, int hp) { | ||
| super(suffix, hp); | ||
| } | ||
| public PoisonSlime(String suffix) { | ||
| super(suffix, 15); // 기본 독슬라임 hp 값: 15 | ||
| } | ||
|
|
||
| @Override | ||
| void attack(Hero hero) { | ||
| super.attack(hero); | ||
|
|
||
| if (poisonCount != 0){ | ||
| System.out.println("추가로 독 포자를 살포했다!"); | ||
| int poisonDemage = (int)(hero.getHp() / 5); | ||
| hero.setHp(hero.getHp() - poisonDemage); | ||
|
|
||
| poisonCount -= 1; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||||||||||||||||||||||||
| package com.survivalcoding; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public class Slime { | ||||||||||||||||||||||||||||||||||||
| final String suffix; | ||||||||||||||||||||||||||||||||||||
| int hp; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public Slime(String suffix, int hp) { | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| public Slime(String suffix) { | ||||||||||||||||||||||||||||||||||||
| this.suffix = suffix; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 7의 생성자가 비어 있어서 🔧 제안 수정안 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| void attack(Hero hero) { | ||||||||||||||||||||||||||||||||||||
| System.out.println("슬라임 " + suffix + "이/가 공격했다" ); | ||||||||||||||||||||||||||||||||||||
| System.out.println("10의 데미지"); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| hero.setHp(hero.getHp() - 10); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class Wizard { | ||
| static final int MAX_MP = 100; | ||
| int hp; | ||
| int mp = MAX_MP; | ||
| Wand wand; | ||
| private String name; | ||
|
|
||
| public int getHp() { | ||
| return hp; | ||
| } | ||
|
|
@@ -14,8 +20,6 @@ public void setHp(int hp) { | |
| this.hp = hp; | ||
| } | ||
|
|
||
| int hp; | ||
|
|
||
| public int getMp() { | ||
| return mp; | ||
| } | ||
|
|
@@ -28,8 +32,6 @@ public void setMp(int mp) { | |
| this.mp = mp; | ||
| } | ||
|
|
||
| int mp; | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
@@ -45,8 +47,6 @@ public void setName(String name) { | |
| this.name = name; | ||
| } | ||
|
|
||
| private String name; | ||
|
|
||
| public Wand getWand() { | ||
| return wand; | ||
| } | ||
|
|
@@ -59,11 +59,11 @@ public void setWand(Wand wand) { | |
| this.wand = wand; | ||
| } | ||
|
|
||
| Wand wand; | ||
|
|
||
| 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); | ||
|
Comment on lines
62
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 67에서 🔧 제안 수정안 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 |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
용어와 오탈자를 바로잡아 주세요.
override/overload는 각각 메서드 재정의 / 메서드 오버로딩을 뜻합니다. 또한클리스,extands,매소드는 오탈자라 문서 신뢰도가 떨어집니다.🛠️ پیشن수정 예시
🤖 Prompt for AI Agents