-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Week1][입문편] 3강 코틀린에서 다양한 클래스를 다루는 방법 (#5)
- Loading branch information
Showing
6 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// 로직 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |