# 다양한 신발 ## 문제 주어진 코드로 출력 예와 같은 결과를 얻으려 한다. 아래의 요구사항을 만족시켜 코드를 완성하시오. #### 요구사항 1. 신발(Shoes)을 추상 클래스로 선언할 것. 2. 신발로 부터 확장된 샌달(Sandals)과 워커(WorkerBoots)의 생성자를 완성할 것. 3. 출력 예와 같은 결과를 얻을 것. ## 출력 예 ``` 샌달 { size: 280mm, price: 85500원, waterproof: true } 워커 { size: 275mm, price: 135000원, weight: 0.98kg } ```
관련 강의로 이동

코드: java 1.8

public class ABCMart { public static void main(String[] args) { // 샌달, 워커 객체 생성 Sandals s = new Sandals(280, 85500, true); WorkerBoots w = new WorkerBoots(275, 135000, 0.98); // 상위 타입의 Shoes 배열 생성 Shoes[] myShoesArr = { s, w }; // 모든 신발 정보 출력 for (int i = 0; i < myShoesArr.length; i++) { Shoes temp = myShoesArr[i]; System.out.println(temp.toString()); } } } /* 1. Shoes 클래스를 추상 클래스로 선언하세요. */ class Shoes { protected int size; protected int price; public Shoes(int size, int price) { this.size = size; this.price = price; } public String toString() { return String.format("신발 { size: %dmm, price: %d원 }", size, price); } } class Sandals extends Shoes { protected boolean waterproof; public Sandals(int size, int price, boolean waterproof) { /* 2. Sandals의 생성자를 완성하세요. */ super(size, price); } public String toString() { return String.format("샌달 { size: %dmm, price: %d원, waterproof: %b }", size, price, waterproof); } } class WorkerBoots extends Shoes { protected double weight; public WorkerBoots(int size, int price, double weight) { /* 3. WorkerBoots의 생성자를 완성하세요. */ } public String toString() { return String.format("워커 { size: %dmm, price: %d원, weight: %.2fkg }", size, price, weight); } }

입력

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