# 대마법사 ## 문제 주어진 뼈대코드는 초심자 클래스를 확장한 마법사 클래스와 이를 다시 확장한 대마법사 클래스가 존재한다. 대마법사에게 보호막(shield) 속성을 추가하고, 에너지볼트 마법과 toString() 메소드를 오버라이딩하여 아래와 같은 결과를 만드시오. ``` [대마법사] 간달프(HP: 100, MP: 100, SHIELD: 100) 간달프의 에너지볼트! (대마법사 버프로 데미지 +30 추가) ```
관련 강의로 이동

코드: java 1.8

public class Main { 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. 보호막 속성을 필드에 추가하시오. */ /* 2. 생성자를 완성하시오. */ public GreatWizard(String name, int hp, int mp, int shield) { } /* 3. toString() 메소드를 오버라이딩 하시오. */ /* 4. 에너지볼트 마법을 오버라이딩 하시오. */ }

입력

정답이 궁금하다면? 코드를 제출해보세요!