-
Notifications
You must be signed in to change notification settings - Fork 18
260616_02_김선진 #55
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
Open
ks98ks-ui
wants to merge
20
commits into
SurvivalCodingCampus:student/02_김선진
Choose a base branch
from
ks98ks-ui:master
base: student/02_김선진
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
260616_02_김선진 #55
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
189ad9c
이름변경
ks98ks-ui ec2d35d
삭제
ks98ks-ui 95cc5e2
문장수정
ks98ks-ui 3bc0b35
나이수정
ks98ks-ui 2263fc3
삭제
ks98ks-ui a81f00f
수정
ks98ks-ui 4e20d42
연습문제4 마법사 수정
ks98ks-ui 8ed8a9c
연습문제4 마법사 수정 테스트코드
ks98ks-ui c5afc6a
상속연습
ks98ks-ui 0448d64
히어로수정
ks98ks-ui 9f16892
연습문제5
ks98ks-ui 5b9eeea
연습문제5 테스트코드
ks98ks-ui a346e36
연습문제1~2
ks98ks-ui 1136908
수정
ks98ks-ui 990801f
슬라임 부모클래스
ks98ks-ui 697b155
연습문제3
ks98ks-ui 4a58170
연습문제3 테스트코드
ks98ks-ui 12f0780
클래스 그림
ks98ks-ui 7d3d925
수정
ks98ks-ui aa9d756
수정
ks98ks-ui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # 2026-06-11 상속 | ||
|
|
||
| ## 오늘 배운 내용 | ||
|
|
||
| - 상속을 받으면 부모 클래스의 생성자를 반드시 호출해야만 한다. | ||
| - @Override를 통해 기존 부모의 것을 가져 올 수 있고 필요하면 수정도 가능하다. | ||
|
|
||
| ## 실습 코드 | ||
|
|
||
| ```java | ||
| public class SuperHero extends Hero { | ||
| public static void main(String[] args) { | ||
| SuperHero superHero = new SuperHero("홍길동", 50); | ||
| superHero.attack(); | ||
| superHero.run(); | ||
| superHero.setFlying(true); | ||
| } | ||
|
|
||
| private boolean isFlying; | ||
|
|
||
| //상속을 받으면 부모 클래스의 생성자를 반드시 호출해야만 한다. | ||
| public SuperHero(String name, int hp) { | ||
| super(name, hp); | ||
| } | ||
|
|
||
|
|
||
| public boolean isFlying() { | ||
| return isFlying; | ||
| } | ||
|
|
||
| public void setFlying(boolean flying) { | ||
| isFlying = flying; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| System.out.println("매우 빠르게 달렸다."); | ||
| } | ||
|
|
||
| @Override | ||
| void attack() { | ||
| super.attack(); | ||
| if (isFlying) { | ||
| System.out.println("한번 더 때려라"); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## 어려웠던 점 | ||
|
|
||
| - 상속받는 클래스 만드는 것과 테스트 코드 짜는법 | ||
|
|
||
| ## 해결 방법 | ||
|
|
||
| - 계속 원하는 바가 안나와서 테스트 코드를 보니 When 순서가 이상해서 안되었다는 걸 알아서 앞으로 When 순서도 잘 생각해서 넣어야한다는 걸 알았습니다. | ||
|
|
||
| ## 내일 더 공부할 것 | ||
|
|
||
| - 상속에 관련 클래스를 더 공부하고 여러개를 만들어볼 것 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| @startuml | ||
| class SuperHero extends Hero { | ||
| +void setFlying(bool flying) | ||
| +boolean isFlying() | ||
| + run()+ | ||
| } | ||
| class Hero { | ||
| - int hp 100 | ||
| - int mp | ||
| - int money 100 | ||
| -String name | ||
| + void attack() | ||
| + run() | ||
| } | ||
| class Cleric { | ||
| - int hp | ||
| - int mp | ||
| - int MaxHP | ||
| - int MaxMP | ||
| - String name | ||
| + selfAid() | ||
| + pray() | ||
| } | ||
| class GreatWizard extends Wizard { | ||
| +heal()+ | ||
| +superHeal() | ||
| } | ||
|
|
||
| class Wizard { | ||
| - int hp | ||
| - int mp = 100 | ||
| - Wand wand | ||
| - String name | ||
| + setWand() | ||
| + heal() | ||
| } | ||
|
|
||
| class Wand { | ||
| - String name | ||
| - double power | ||
| } | ||
|
|
||
| class Person { | ||
| -int age | ||
| -String name | ||
| -int birthYear | ||
| } | ||
| class PoisonSlime extends Slime { | ||
| +attack()+ | ||
| } | ||
|
|
||
| class Slime { | ||
| -String suffix | ||
| -int hp | ||
| +attack() | ||
| } | ||
|
|
||
|
|
||
| @enduml |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| 슈퍼클래스 서브클래스 | ||
| 1 Person Student | ||
| 2 Car Engine | ||
| 3 Father Child | ||
| 4 Food Susi | ||
| 5 SuperMan Man | ||
|
|
||
| 2, 3, 5 | ||
|
|
||
| 부모 클래스와 자식 클래스 1개씩 | ||
|
|
||
| 기계 기계 책 | ||
| Phone Car Dictionary | ||
| 아이폰 슈퍼카 영어사전 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| import static com.survivalcoding.Hero.MaxHP; | ||
|
|
||
| public class GreatWizard extends Wizard { | ||
| private int Mp = 150; | ||
|
|
||
| @Override | ||
| public int getMp() { | ||
| return Mp; | ||
| } | ||
|
|
||
| @Override | ||
| public void setMp(int mp) { | ||
| Mp = mp; | ||
| } | ||
|
|
||
| public GreatWizard() { | ||
| super(); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| void heal(Hero hero) { | ||
| int basePoint = 25; | ||
| int baseMp = 5; | ||
|
|
||
| if (this.getMp() >= 5) { | ||
| hero.setHp(hero.getHp() + basePoint); | ||
| this.setMp(this.getMp() - baseMp); | ||
| System.out.println("힐을 시전했습니다."); | ||
| System.out.println(hero + "HP :" + hero.getHp()); | ||
| } else { | ||
| System.out.println("마나가 부족합니다"); | ||
| } | ||
| } | ||
|
|
||
| void superHeal(Hero hero) { | ||
|
|
||
| int basePoint = MaxHP; | ||
| int baseMp = 50; | ||
|
|
||
|
|
||
| if (this.getMp() >= 50) { | ||
| hero.setHp(basePoint); | ||
| this.setMp(this.getMp() - baseMp); | ||
| System.out.println("슈퍼 힐을 시전했습니다"); | ||
| System.out.println(hero + "HP :" + hero.getHp()); | ||
| } else { | ||
| System.out.println("마나가 부족합니다"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| public class Hero { | ||
| public static int money = 100; | ||
| public static int MaxHP = 100; | ||
|
|
||
| private String name; | ||
| private int hp; | ||
|
|
@@ -13,6 +14,21 @@ public int getHp() { | |
| } | ||
|
|
||
| public void setHp(int hp) { | ||
| if (hp < 0) { | ||
| hp = 0; | ||
| } | ||
| this.hp = hp; | ||
| } | ||
|
|
||
| public Hero() { | ||
| this.name = "홍길동"; | ||
| this.hp = 100; | ||
| System.out.println("홍길동 생성자"); | ||
|
|
||
| } | ||
|
|
||
| public Hero(String name, int hp) { | ||
| this.name = name; | ||
| this.hp = hp; | ||
| } | ||
|
Comment on lines
+30
to
33
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 음수 클램프 계약을 우회합니다. Line 30-33에서 제안 수정안 public Hero(String name, int hp) {
this.name = name;
- this.hp = hp;
+ setHp(hp);
}🤖 Prompt for AI Agents |
||
|
|
||
|
|
@@ -40,6 +56,10 @@ void attack() { | |
| hp -= 1; | ||
| System.out.println("공격했다"); | ||
| } | ||
|
|
||
| public void run() { | ||
| System.out.println("달렸다"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class PoisonSlime extends Slime { | ||
| private int poisonCount = 5; | ||
|
|
||
| public int getPoisonCount() { | ||
| return poisonCount; | ||
| } | ||
|
|
||
| public void setPoisonCount(int poisonCount) { | ||
| this.poisonCount = poisonCount; | ||
| } | ||
|
|
||
| public PoisonSlime(String name) { | ||
| super(name); | ||
| } | ||
|
|
||
| @Override | ||
| void attack(Hero hero) { | ||
|
|
||
| if (this.getPoisonCount() > 0) { | ||
| super.attack(hero); | ||
| System.out.println("추가로, 독 포자를 살포했다!"); | ||
| hero.setHp(hero.getHp() - (int) (hero.getHp()) / 5); | ||
| System.out.println("~포인트 데미지"); | ||
| this.poisonCount--; | ||
| } else { | ||
| super.attack(hero); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class Slime { | ||
| final String suffix; | ||
| int hp; | ||
|
|
||
| public Slime(String suffix) { | ||
| this.suffix = suffix; | ||
| } | ||
|
|
||
| void attack(Hero hero) { | ||
| System.out.println("슬라임" + suffix + "이/가 공격했다"); | ||
| System.out.println("10의 데미지"); | ||
|
|
||
| hero.setHp((hero.getHp()) - 10); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.survivalcoding; | ||
|
|
||
| public class SuperHero extends Hero { | ||
| public static void main(String[] args) { | ||
| SuperHero superHero = new SuperHero("홍길동", 50); | ||
| superHero.attack(); | ||
| superHero.run(); | ||
| superHero.setFlying(true); | ||
| } | ||
|
|
||
| private boolean isFlying; | ||
|
|
||
| //상속을 받으면 부모 클래스의 생성자를 반드시 호출해야만 한다. | ||
| public SuperHero(String name, int hp) { | ||
| super(name, hp); | ||
| } | ||
|
|
||
|
|
||
| public boolean isFlying() { | ||
| return isFlying; | ||
| } | ||
|
|
||
| public void setFlying(boolean flying) { | ||
| isFlying = flying; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| System.out.println("매우 빠르게 달렸다."); | ||
| } | ||
|
|
||
| @Override | ||
| void attack() { | ||
| super.attack(); | ||
| if (isFlying) { | ||
| System.out.println("한번 더 때려라"); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
setMp오버라이드가 상위 클래스의 음수 MP 방어 계약을 깨고 있습니다.Line 14-16은 음수 MP를 그대로 허용합니다.
Wizard.setMp()는 음수 입력을 예외 처리하므로, 하위 클래스도 동일 제약을 유지해야 타입 대체가 안전합니다.제안 수정안
`@Override` public void setMp(int mp) { - Mp = mp; + if (mp < 0) { + throw new IllegalArgumentException("마법사의 MP는 0 이상이여야 한다"); + } + Mp = mp; }📝 Committable suggestion
🤖 Prompt for AI Agents