Skip to content

Commit

Permalink
[Week1][입문편] 3강 코틀린에서 다양한 클래스를 다루는 방법 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjsmk0902 committed Jun 26, 2024
1 parent e9ff193 commit b74030b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 양승민/입문/src/lec14/java/JavaCountry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lec14.java;

public enum JavaCountry {

KOREA("KO"),
AMERICA("US");

private final String code;

JavaCountry(String code) {
this.code = code;
}

public String getCode() {
return code;
}

private static void handleCountry(JavaCountry country) {
if (country == JavaCountry.KOREA) {
// 로직
}

if (country == JavaCountry.AMERICA) {
// 로직
}
}
}
12 changes: 12 additions & 0 deletions 양승민/입문/src/lec14/java/JavaPersonDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package lec14.java;

public class JavaPersonDto {

private final String name;
private final int age;

public JavaPersonDto(String name, int age) {
this.name = name;
this.age = age;
}
}
15 changes: 15 additions & 0 deletions 양승민/입문/src/lec14/kotlin/Country.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package lec14.kotlin

enum class Country(
val code: String,
) {
KOREA("KO"),
AMERICA("US");

private fun handleCountry(country: Country) {
when (country) {
KOREA -> TODO()
AMERICA -> TODO()
}
}
}
14 changes: 14 additions & 0 deletions 양승민/입문/src/lec14/kotlin/HyundaiCar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package lec14.kotlin

sealed class HyundaiCar(
val name: String,
val price: Long
) {

class Avante : HyundaiCar("아반떼", 1_000L)

class Sonata : HyundaiCar("소나타", 2_000L)

class Grandeur : HyundaiCar("그렌저", 3_000L)

}
6 changes: 6 additions & 0 deletions 양승민/입문/src/lec14/kotlin/PersonDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package lec14.kotlin

data class PersonDto(
private val name: String,
private val age: Int
)
13 changes: 13 additions & 0 deletions 양승민/입문/src/lec14/kotlin/lec14Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package lec14.kotlin

fun main() {
handleCar(HyundaiCar.Avante())
}

private fun handleCar(car: HyundaiCar) {
when (car) {
is HyundaiCar.Avante -> TODO()
is HyundaiCar.Sonata -> TODO()
is HyundaiCar.Grandeur -> TODO()
}
}

0 comments on commit b74030b

Please sign in to comment.