# 쇼핑 장바구니 ## 문제 상품객체를 장바구니에 담고, 이를 모두 출력하려 한다. 뼈대코드에 `클래스 다이어그램`을 구현하여 출력 예와 같은 결과를 얻으시오. ## 클래스 다이어그램 ![Imgur](https://i.imgur.com/pdfq0p7.png) ## 출력 예 ``` FHD 와이드 모니터: 450000원 5K 벽걸이 TV: 2350000원 노트북 고급형: 1650000원 ``` ## 뼈대코드 ``` import java.util.ArrayList; public class ShoppingList { public static void main(String[] args) { // 상품 객체 생성 Goods monitor = new Monitor("FHD 와이드 모니터", 450000); Goods tv = new TV("5K 벽걸이 TV", 2350000); Goods computer = new Computer("노트북 고급형", 1650000); // 장바구니에 담기 ArrayList<Goods> cart = new ArrayList<Goods>(); cart.add(monitor); cart.add(tv); cart.add(computer); // 장바구니 내역 출력 for (Goods g : cart) { System.out.println(g.toString()); } } } abstract class Goods { /* (1) 추상 클래스의 필드를 추가하시오. */ /* (2) 추상 클래스의 생성자를 추가하시오. */ /* (3) 추상 클래스의 toString() 메소드를 오버라이딩하시오. */ } class Monitor extends Goods { public Monitor(String name, int price) { super(name, price); } } class TV extends Goods { public TV(String name, int price) { super(name, price); } } class Computer extends Goods { public Computer(String name, int price) { super(name, price); } } ```
관련 강의로 이동

코드: java 1.8

public class Main { public static void main(String[] args) { } }

입력

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