728x90
피드백
- 프로퍼티에 underbar를 붙이는건 kotlin 코드 컨벤션에 맞지 않습니다.
- Order를 data class로 했으면 더 좋겠습니다.
ㄴ
fun purchaseFun(_money: Double, total: Double): Double {
var money = _money
} 이런 패턴은 지양해야합니다.
- Order를 data class로 했으면 더 좋겠습니다.
- Const.kt는 상수 클래스인데, 구현내용은 상수가 아닙니다. 목적에 맞는 클래스 이름으로 생성해주세요.
- kotlin 가드에서는 Pair, Triple를 사용하고 4개 이상부터는 data class를 설계하라고 가이드하는데요. Triple 사용할 이유가 있다면 data class 를 생성해서 사용하는게 코드 가독성, 확장성 측면에서 유리합니다.
정리하면
- 프로퍼티 이름에는 언더바("_")를 사용하지 않는다.
- 사용한 클래스를 Data Class 로 만들면 더 좋다.
- 날짜를 전역변수로 지정하기 위한 클래스인 Const.kt의 이름과 내용이 맞지 않는다.
- Triple 이상의 데이터 짝?을 사용한다면 별개의 Data Class를 선언하는 편이 좋다.
피드백 반영
package com.example.week3_homework
import kotlin.math.round
class BillList(inputOrdered: MutableList<Order>) {
private val ordered = inputOrdered // _ordered -> inputOrdered로 변경
fun printBill() {
if (ordered.isEmpty()) {
println("주문 목록이 비어있습니다.")
} else {
println("순번\t| 품목 명\t\t\t| 가격\t\t| 개수\t| 총가격")
for (i in 0..ordered.lastIndex) {
println("${i + 1}\t| ${ordered[i].name}\t| $ ${ordered[i].price}\t| ${ordered[i].count} \t| $ ${ordered[i].totalPrice}")
}
println("총 금액\t\t\t\t\t\t\t\t\t\t| $ ${ordered.sumOf { it.totalPrice }}")
}
}
fun getNumFun(): Int {
println("\n사용하실 기능을 선택해주세요.")
println("1.\t결제하기\t2.\t초기화하기\t3.\t추가주문하기")
while (true) {
val input = readln().toIntOrNull() ?: -1
when (input) {
1, 2, 3 -> return input
else -> {
println("올바른 숫자를 입력해주세요.")
}
}
}
}
fun purchaseFun(inputMoney: Double, total: Double): Double {
var money = inputMoney // _money -> inputMoney로 변경
val changes = round((money - total) * 10) / 10
if (money >= total) {
println("총 \$ ${money} 중 \$ ${total}을 지불해 \$ ${changes} 남았습니다.")
println("결제가 완료되었습니다. \t(${localDateTime.format(formatter)})")
money = changes
} else {
println("금액이 \$ ${-changes}만큼 모자랍니다. 주문목록을 초기화합니다.")
}
return money
}
}
우선 1번과 2번 피드백을 반영했다. _가 포함된 프로퍼티의 이름을 전부 바꾸었다.
data class Order(val name: String, val price: Double, val count: Int) {
val totalPrice = round(price * count * 10) / 10
}
Order Class에도 있던 _를 제거하고 data Class로 바꾸었다.
또한 3번 피드백을 적용해 Const.kt -> Date.kt로 바꾸었다.
data class MenuBoard(val name: String, val price: Double, val introduce: String)
4번 피드백을 적용해 Triple -> data Class인 MenuBoard를 만들었다.
728x90
'개발' 카테고리의 다른 글
| 03/20 주특기 1주차 개인과제(2) (0) | 2024.03.20 |
|---|---|
| 03/19 주특기 1주차 개인과제(1) (0) | 2024.03.19 |
| 03/12 간단한 키오스크 만들기(3) (0) | 2024.03.12 |
| 03/11 간단한 키오스크 만들기(2) (0) | 2024.03.11 |
| 03/11 간단한 키오스크 만들기(1) (0) | 2024.03.11 |