# 인터페이스와 ArrayList #### CODE <a class='btn btn-default' href='/codes/27052'>Link</a> ``` public class InterfaceType { public static void main(String[] args) { Food f = new Food("족발", 19800); Electronics e = new Electronics("에어팟", 199900); Clothing c = new Clothing("셔츠", 49900); int sum = f.discountedPrice()+e.discountedPrice()+c.discountedPrice(); System.out.printf("총합: %d원", sum); } } interface Orderable { public int discountedPrice(); } class Food implements Orderable { private String name; private int price; public Food(String name, int price) { this.name = name; this.price = price; } public int discountedPrice(){ return (int)(price*0.9); } } class Electronics implements Orderable { private String name; private int price; public Electronics(String name, int price) { this.name = name; this.price = price; } public int discountedPrice(){ return (int)(price*0.8); } } class Clothing implements Orderable { private String name; private int price; public Clothing(String name, int price) { this.name = name; this.price = price; } public int discountedPrice(){ return (int)(price*0.7); } } ``` #### INPUT ``` ``` #### OUPUT ``` 총합: 212670원 ``` 계산기로 계산하면 212,670이 나오는 것 같습니다만..
Electronics 객체 만드실때 에어팟 가격이 잘못 들어갔습니다. -------------------------------------- Electronics e = new Electronics("에어팟", 199900); 199900원에서 199000으로 넣어주셔야 합니다.