-
Notifications
You must be signed in to change notification settings - Fork 18
260616_10_박승빈 #61
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/10_박승빈
Are you sure you want to change the base?
260616_10_박승빈 #61
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,22 @@ | ||
| 11장 상속 연습문제 | ||
|
|
||
| #문제 1 | ||
|
|
||
| **정답** : 2,3,5 | ||
|
|
||
| 2번 : 엔진은 자동차의 부품이지만 자동차는 아니다 | ||
|
|
||
| 3번 : 자식은 아버지가 아니다 | ||
|
|
||
| 5번 : 서로의 개념이 바뀌었음 | ||
|
|
||
| #문제 2 | ||
|
|
||
| **정답** : | ||
|
|
||
| (1) : 부모클래스 - Electronic devices / 자식클래스 - iphone | ||
|
|
||
| (2) : 부모클래스 - Transportation / 자식클래스 - bmw | ||
|
|
||
| (3) : 부모클래스 - BOOK / 자식클래스 - EnglishDictionary | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class GreatWizard extends Wizard { | ||
|
|
||
| public GreatWizard() { | ||
| this.mp = 150; | ||
| this.heal = 25; | ||
| this.mpCost = 5; | ||
| } | ||
|
|
||
| public void heal(Hero hero) { | ||
| super.heal(hero); | ||
| } | ||
|
|
||
| public void superHeal(Hero hero) { | ||
| if (this.mp >= 50) { | ||
| hero.setHp(Hero.MAX_HP); | ||
| this.mp -= 50; | ||
| System.out.println("슈퍼 힐을 시전했습니다. " + hero.name + "HP : " + hero.getHp()); | ||
| } else { | ||
| System.out.println("마나가 부족합니다"); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,72 @@ | ||||||||||||||
| package com.survivalcoding; | ||||||||||||||
|
|
||||||||||||||
| import java.util.Random; | ||||||||||||||
|
|
||||||||||||||
| public class Hero { | ||||||||||||||
| static final int MAX_HP = 100; | ||||||||||||||
| static int money = 100; | ||||||||||||||
|
|
||||||||||||||
| String name; | ||||||||||||||
| int hp; | ||||||||||||||
| Sword sword; | ||||||||||||||
|
|
||||||||||||||
| Hero() { | ||||||||||||||
| this.name = "임용사"; | ||||||||||||||
| this.hp = 100; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Hero(String name) { | ||||||||||||||
| this.name = name; | ||||||||||||||
| this.hp = 99; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public Hero(String name, int hp) { | ||||||||||||||
| this.name = name; | ||||||||||||||
| this.hp = hp; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public int getHp() { | ||||||||||||||
| return this.hp; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public void setHp(int hp) { | ||||||||||||||
| this.hp = Math.min(hp, MAX_HP); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+32
to
+34
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 32-34에서 상한만 제한해 음수값이 그대로 저장됩니다. 전투/독 데미지 누적 시 HP가 음수로 내려가 UI/로직이 깨질 수 있습니다. 수정 제안 public void setHp(int hp) {
- this.hp = Math.min(hp, MAX_HP);
+ this.hp = Math.max(0, Math.min(hp, MAX_HP));
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| static void setRandomMoney() { | ||||||||||||||
| money = new Random().nextInt(1000); | ||||||||||||||
| System.out.println("초기금 : " + money); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // 나는 공격하면 hp 가 1씩 빠진다 | ||||||||||||||
| void attack() { | ||||||||||||||
| hp -= 1; | ||||||||||||||
| // sout | ||||||||||||||
| System.out.println("공격했다"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void run() { | ||||||||||||||
| System.out.println(this.name + "는 도망쳤다!"); | ||||||||||||||
| System.out.println("GAME OVER"); | ||||||||||||||
| System.out.println("최종 HP는" + this.hp + "입니다"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void sit(int sec) { | ||||||||||||||
| //앉은 초 수만큼 hp 증가 | ||||||||||||||
| this.hp += sec; | ||||||||||||||
|
|
||||||||||||||
| System.out.println(this.name + "는" + sec + "초 앉았다"); | ||||||||||||||
| System.out.println("HP가" + sec + "포인트 회복되었다"); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+54
to
+60
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. HP 변경 로직이 setter를 우회해 상한/하한 계약이 깨집니다. Line 54-60, 68-70에서 수정 제안 void sit(int sec) {
- this.hp += sec;
+ setHp(this.hp + sec);
System.out.println(this.name + "는" + sec + "초 앉았다");
System.out.println("HP가" + sec + "포인트 회복되었다");
}
void sleep() {
- this.hp = 100;
+ setHp(MAX_HP);
System.out.println(this.name + "는 잠을 자고 회복했다!");
}Also applies to: 68-70 🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| void slip() { | ||||||||||||||
| this.hp -= 5; | ||||||||||||||
| System.out.println(this.name + "는 넘어졌다!"); | ||||||||||||||
| System.out.println("5의 데미지!"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void sleep() { | ||||||||||||||
| this.hp = 100; | ||||||||||||||
| System.out.println(this.name + "는 잠을 자고 회복했다!"); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| 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 | ||
| public 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 + "포인트 데미지"); | ||
| this.poisonCount--; //독 공격 가능 횟수 차감 | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class Slime { | ||
| final String suffix; | ||
| int hp; | ||
|
|
||
| public Slime(String suffix) { | ||
| this.suffix = suffix; | ||
| } | ||
|
|
||
| public String getSuffix() { | ||
| return this.suffix; | ||
| } | ||
|
|
||
| public int getHp() { | ||
| return this.hp; | ||
| } | ||
|
|
||
| public void setHp(int hp) { | ||
| this.hp = hp; | ||
| } | ||
|
|
||
| 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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||
| package com.survivalcoding; | ||||||||||||||||||
|
|
||||||||||||||||||
| public class Wizard { | ||||||||||||||||||
| String name; | ||||||||||||||||||
| int hp; | ||||||||||||||||||
| //protected : 자식클래스 사용 가능하도록 만듬 | ||||||||||||||||||
| protected int heal = 20; | ||||||||||||||||||
| protected int mp = 100; | ||||||||||||||||||
| protected int mpCost = 10; | ||||||||||||||||||
|
|
||||||||||||||||||
| public void heal(Hero hero) { | ||||||||||||||||||
| System.out.println("현재 체력 : " + hero.getHp()); | ||||||||||||||||||
| if (this.mp >= 10) { | ||||||||||||||||||
| hero.setHp(hero.getHp() + heal); | ||||||||||||||||||
| this.mp -= mpCost; | ||||||||||||||||||
| System.out.println("힐을 시전했습니다. " + hero.name + "HP : " + hero.getHp()); | ||||||||||||||||||
|
Comment on lines
+13
to
+16
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 13에서 수정 제안- if (this.mp >= 10) {
+ if (this.mp >= this.mpCost) {
hero.setHp(hero.getHp() + heal);
this.mp -= mpCost;
System.out.println("힐을 시전했습니다. " + hero.name + "HP : " + hero.getHp());📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } else { | ||||||||||||||||||
| System.out.println("마나가 부족합니다"); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
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.
ATX 헤딩 뒤 공백 누락(MD018) 수정이 필요합니다.
Line 3, Line 13의
#문제형식은 markdownlint 경고 대상입니다.# 문제로 공백을 넣어 주세요.수정 제안
Also applies to: 13-13
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 3-3: No space after hash on atx style heading
(MD018, no-missing-space-atx)
🤖 Prompt for AI Agents
Source: Linters/SAST tools