햄버거 주문 앱

Dec 27, 2023
햄버거 주문 앱
 

롯데리아 앱

package ex07.programming.ex06.example7; public class LotteApp { public static void main(String[] args) { Burger b1 = new Burger("기본 버거", 1000); Burger b2 = new ShrimpBurger("새우 버거", 2000, "새우"); Coke c1 = new Coke("콜라", 1000); System.out.println(); BurgerSet set1 = new BurgerSet(new Burger("기본 버거", 1000), new Coke("콜라", 1000)); System.out.println("총 가격은 " + set1.getTotalPrice()); } }
 

기본 버거 클래스

package ex07.programming.ex06.example7; public class Burger { private String name; private int price; public Burger(String name, int price) { this.name = name; this.price = price; System.out.println(name + "가 만들어졌어요."); } public String getName() { return name; } public int getPrice() { return price; } };
 

새우 버거 클래스

package ex07.programming.ex06.example7; public class ShrimpBurger extends Burger { private String material; public ShrimpBurger(String name, int price, String material) { super(name, price); this.material = material; } public String getMaterial() { return material; } }
 
package ex07.programming.ex06.example7; public class Coke { private String name; private int price; public Coke(String name, int price) { this.name = name; this.price = price; System.out.println(name + "가 만들어졌어요."); } public String getName() { return name; } public int getPrice() { return price; } }
 

버거 세트 클래스

package ex07.programming.ex06.example7; public class BurgerSet { // has Burger, Coke private Burger burger; // 컴포지션 결합 코드 private Coke coke; public BurgerSet(Burger burger, Coke coke) { this.burger = burger; this.coke = coke; System.out.println("버거 세트가 만들어졌어요. "); } public int getTotalPrice() { return burger.getPrice() + coke.getPrice(); } public Burger getBurger() { return burger; } public Coke getCoke() { return coke; } }
 
Share article

hyeonjeong-jang-0302