-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain4.java
More file actions
68 lines (57 loc) · 1.68 KB
/
Copy pathMain4.java
File metadata and controls
68 lines (57 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package javaExF;
public class Main4 {
public static void main(String[] args) {
// 객체 생성
GreatWizard gandalf = new GreatWizard("간달프", 100, 100, 100);
// 상태 출력
System.out.println(gandalf.toString());
// 에너지볼트
gandalf.energeVolt();
}
}
class Novice {
// 필드
protected String name;
protected int hp;
// 생성자
public Novice(String name, int hp) {
this.name = name;
this.hp = hp;
}
// toString
public String toString() {
return String.format("[Novice] %s(HP: %d)", this.name, this.hp);
}
}
class Wizard extends Novice {
// 필드
protected int mp;
// 생성자
public Wizard(String name, int hp, int mp) {
super(name, hp);
this.mp = mp;
}
// 에너지볼트
public void energeVolt() {
System.out.printf("%s의 에너지볼트!\n", this.name);
}
}
class GreatWizard extends Wizard {
/* 1. 보호막 속성을 필드에 추가하시오. */
int shield;
/* 2. 생성자를 완성하시오. */
public GreatWizard(String name, int hp, int mp, int shield) {
super(name, hp, mp);
this.shield = shield;
}
/* 3. toString() 메소드를 오버라이딩 하시오. */
@Override
public String toString() {
return String.format("[대마법사] %s(HP: %d, MP: %d, SHIELD: %d)", super.name, super.hp, super.mp, this.shield);
}
/* 4. 에너지볼트 마법을 오버라이딩 하시오. */
@Override
public void energeVolt() {
System.out.printf("%s의 에너지볼트! (대마법사 버프로 데미지 +30 추가)\n", super.name);
}
}