과제/키오스크
kiosk 과제 lv2
crablo
2024. 3. 11. 18:57
728x90
이번에는 kiosk 과제 lv2를 진행하였다.
- 필요한 클래스들을 설계합니다.(버거, 아이스크림, 음료, 맥주, 주문, 공통 등)
- 클래스들의 `**프로퍼티**`와 `**메소드**`를 정의합니다
- 예를 들어 아래 이미지처럼 클래스 다이어그램을 그려봅시다.
- 햄버거는 이름, 가격 같은 프로퍼티와 정보를 출력하는 메소드가 있을 수 있죠?
- **`Lv1`**에서 작성한 로직을 메소드로 만듭니다.
나는 기존과 동일하게 서브웨이 메뉴로 진행했다.
각각의 메뉴별 클래스를 따로 만들고 각 메뉴별로 프로퍼티와 메서드를 따로따로 적었다.
package com.ellycrab.kiosklv2
class SandWiches {
//샌드위치 프로퍼티
val sandwichOptions = listOf("Egg Slice", "Italian BMT", "Chicken Bacon Avocado",
"Rotisserie Barbecue", "Shrimp", "Roasted Chicken")
//샌드위치 메서드
//세부메뉴 전체
fun displaySandwiches(){
println("샌드위치 세부옵션을 선택해주세요.:")
sandwichOptions.forEachIndexed{
index,value->
println("${index+1}.$value")
}
}
//세부메뉴 선택(주문)
fun orderSandwich(choice:Int):String?{
if(choice in 1..sandwichOptions.size){
return sandwichOptions[choice-1]
}
println("유효하지 않은 번호를 선택하셨습니다.")
return null
}
}
[Sandwiches.kt]
프로퍼티에는 세부 메뉴리스트가 담기고 메서드는 세부옵션 메뉴 목록과 메뉴번호 선택하는 함수가 있다.
전체 파일은 깃에 올려놨다.
https://github.com/ellycrab/kiosk/tree/eunKiosk
GitHub - ellycrab/kiosk: 키오스크과제
키오스크과제. Contribute to ellycrab/kiosk development by creating an account on GitHub.
github.com
728x90