-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from dicodingacademy/separate-question-and-exa…
…m-file Separate `instruction` and `exam` code for Better Clarity
- Loading branch information
Showing
42 changed files
with
797 additions
and
459 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,16 @@ | ||
package com.dicoding.exam.exam1 | ||
|
||
// TODO 1 | ||
fun isEvenNumber(number: Int): Boolean { | ||
return false | ||
} | ||
|
||
// TODO 2 | ||
fun moreThanFive(number: Int): Boolean { | ||
return false | ||
} | ||
|
||
// TODO 3 | ||
fun result(number: Int): Int { | ||
return 0 | ||
} |
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,19 @@ | ||
package com.dicoding.exam.exam1 | ||
|
||
private fun main() { | ||
println( | ||
""" | ||
${isEvenNumber(1)} | ||
${moreThanFive(1)} | ||
${result(1)} | ||
""".trimIndent() | ||
) | ||
|
||
println( | ||
""" | ||
${isEvenNumber(10)} | ||
${moreThanFive(10)} | ||
${result(10)} | ||
""".trimIndent() | ||
) | ||
} |
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,89 @@ | ||
# Exam 1 - Fundamental | ||
|
||
## Ketentuan | ||
|
||
**Agar dapat diperiksa dengan baik, hindari beberapa hal berikut:** | ||
|
||
1. Mengubah kode fungsi `main()` yang berada di dalam file `Exam1Main.kt` | ||
2. Menghapus atau mengubah nama fungsi dan variable yang sudah ada di dalam file `Exam1.kt` | ||
3. Membuat fungsi baru yang bukan merupakan tugas latihan | ||
4. Mengubah struktur project (menghapus, mengedit, dan memindahkan package) | ||
|
||
## Instruksi | ||
|
||
Untuk mengerjakan soal latihan ini, silakan buka file `Exam1.kt`. | ||
|
||
### TODO 1 | ||
|
||
Sesuaikan fungsi `isEvenNumber` dengan kode untuk mengecek apakah parameter number merupakan **angka genap**. | ||
|
||
```kotlin | ||
fun isEvenNumber(number: Int) = false | ||
``` | ||
|
||
#### Contoh 1: | ||
|
||
- Masukan: `number` = `77` | ||
- Keluaran: `false` | ||
- Penjelasan: Angka `77` merupakan angka ganjil. | ||
|
||
#### Contoh 2: | ||
|
||
- Masukan: `number` = `88` | ||
- Keluaran: `true` | ||
- Penjelasan: Angka `88` merupakan angka genap. | ||
|
||
### TODO 2 | ||
|
||
Sesuaikan fungsi `moreThanFive` dengan kode untuk mengecek apakah parameter number **lebih dari 5**. | ||
|
||
```kotlin | ||
fun moreThanFive(number: Int) = false | ||
``` | ||
|
||
#### Contoh 1: | ||
|
||
- Masukan: `number` = `5` | ||
- Keluaran: `false` | ||
- Penjelasan: Angka `5` tidak lebih dari angka `5`. | ||
|
||
#### Contoh 2: | ||
|
||
- Masukan: `number` = `88` | ||
- Keluaran: `true` | ||
- Penjelasan: Angka `88` lebih dari angka `5`. | ||
|
||
### TODO 3 | ||
|
||
Sesuaikan fungsi `result` agar dapat menghasilkan nilai akhir dengan rumus: | ||
|
||
```text | ||
result = number x (number + 10) | ||
``` | ||
|
||
#### Contoh 1: | ||
|
||
- Masukan: `number` = `1` | ||
- Keluaran: `11` | ||
- Penjelasan: 1 x (1 + 10) = 11 | ||
|
||
#### Contoh 2: | ||
|
||
- Masukan: `number` = `10` | ||
- Keluaran: `200` | ||
- Penjelasan: 10 x (10 + 10) = 200 | ||
|
||
## Menguji Kode | ||
|
||
Untuk menguji kode, silakan jalankan fungsi `main` pada file `Exam1Main.kt`. | ||
|
||
Jika kode pada `Exam1.kt` sudah diperbaiki sesuai ketentuan, maka keluarannya akan seperti berikut: | ||
|
||
``` | ||
false | ||
false | ||
11 | ||
true | ||
true | ||
200 | ||
``` |
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,11 @@ | ||
package com.dicoding.exam.exam2 | ||
|
||
// TODO 1 | ||
fun calculate(valueA: Int, valueB: Int, valueC: Int?): Int { | ||
return 0 | ||
} | ||
|
||
// TODO 2 | ||
fun result(result: Int): String { | ||
return "" | ||
} |
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,17 @@ | ||
package com.dicoding.exam.exam2 | ||
|
||
private fun main() { | ||
val valueA = 101 | ||
val valueB = 52 | ||
val valueC = 99 | ||
|
||
val resultA = calculate(valueA, valueB, valueC) | ||
val resultB = calculate(valueA, valueB, null) | ||
|
||
println( | ||
""" | ||
${result(resultA)} | ||
${result(resultB)} | ||
""".trimIndent() | ||
) | ||
} |
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,71 @@ | ||
# Exam 2 - Control Flow | ||
|
||
## Ketentuan | ||
|
||
**Agar dapat diperiksa dengan baik, hindari beberapa hal berikut:** | ||
|
||
1. Mengubah kode fungsi `main()` yang berada di dalam file `Exam2Main.kt` | ||
2. Menghapus atau mengubah nama fungsi dan variable yang sudah ada di dalam file `Exam2.kt` | ||
3. Membuat fungsi baru yang bukan merupakan tugas latihan | ||
4. Mengubah struktur project (menghapus, mengedit, dan memindahkan package) | ||
|
||
## Instruksi | ||
|
||
Untuk mengerjakan soal latihan ini, silakan buka file `Exam2.kt`. | ||
|
||
### TODO 1 | ||
|
||
Sesuaikan fungsi `calculate` agar dapat menghasilkan nilai akhir dengan rumus: | ||
|
||
```text | ||
calculate = valueA + (valueB - valueC) | ||
``` | ||
|
||
Namun, jika `valueC` bernilai `null`, silakan tetapkan nilai `50` sebagai nilai _default_-nya. | ||
|
||
#### Contoh 1: | ||
|
||
- Masukan: `valueA` = `101`, `valueB` = `52`, `valueC` = `99` | ||
- Keluaran: `54` | ||
- Penjelasan: Hasil dari pertingungan `101 x (52 - 99)` adalah `54`. | ||
|
||
#### Contoh 2: | ||
|
||
- Masukan: `valueA` = `101`, `valueB` = `52`, `valueC` = `null` | ||
- Keluaran: `103` | ||
- Penjelasan: | ||
- Dikarenakan `valueC` bernilai `null`, maka digantikan oleh nilai _default_-nya yaitu `50`. Sehingga, hasil dari | ||
pertingungan `101 x (52 - 50)` adalah `103`. | ||
|
||
### TODO 2 | ||
|
||
Sesuaikan fungsi `result` ini dapat mengembalikkan text seperti berikut: | ||
|
||
```markdown | ||
Result is $result | ||
``` | ||
|
||
Di mana `$result` adalah argumen dari fungsi tersebut. | ||
|
||
#### Contoh 1: | ||
|
||
- Masukan: `result` = `54` | ||
- Keluaran: `Result is 54` | ||
- Penjelasan: String `Result is` ditambah dengan argumen result bernilai `54`. | ||
|
||
#### Contoh 2: | ||
|
||
- Masukan: `number` = `103` | ||
- Keluaran: `Result is 103` | ||
- Penjelasan: String `Result is` ditambah dengan argumen result bernilai `103`. | ||
|
||
## Menguji Kode | ||
|
||
Untuk menguji kode, silakan jalankan fungsi `main` pada file `Exam2Main.kt`. | ||
|
||
Jika kode pada `Exam2.kt` sudah diperbaiki sesuai ketentuan, maka keluarannya akan seperti berikut: | ||
|
||
``` | ||
Result is 54 | ||
Result is 103 | ||
``` |
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 com.dicoding.exam.exam3 | ||
|
||
// TODO | ||
fun <T> checkType(args: T): String { | ||
return "" | ||
} |
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 com.dicoding.exam.exam3 | ||
|
||
private fun main() { | ||
println( | ||
""" | ||
'Dicoding Indonesia' is String? ${checkType("Dicoding Indonesia")} | ||
'True' is Boolean? ${checkType(true)} | ||
'1' is Integer? ${checkType(1)} | ||
'10.01' is Double? ${checkType(10.01)} | ||
'[10, 9, 8 , 6]' is List? ${checkType(listOf(10, 9, 8, 6))} | ||
'{score=10}' is Map? ${checkType(mapOf("score" to 10))} | ||
""".trimIndent() | ||
) | ||
} |
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,65 @@ | ||
# Exam 3 - Generics | ||
|
||
## Ketentuan | ||
|
||
**Agar dapat diperiksa dengan baik, hindari beberapa hal berikut:** | ||
|
||
1. Mengubah kode fungsi `main()` yang berada di dalam file `Exam3Main.kt` | ||
2. Menghapus atau mengubah nama fungsi dan variable yang sudah ada di dalam file `Exam3.kt` | ||
3. Membuat fungsi baru yang bukan merupakan tugas latihan | ||
4. Mengubah struktur project (menghapus, mengedit, dan memindahkan package) | ||
|
||
## Instruksi | ||
|
||
Untuk mengerjakan soal latihan ini, silakan buka file `Exam3.kt`. | ||
|
||
### TODO | ||
|
||
Lengkapi fungsi `checkType` agar dapat mengembalikkan tipe nilai sesuai dengan parameter yang dilampirkan. Format | ||
keluaran yang diharapkan adalah sebagai berikut: | ||
|
||
```markdown | ||
Yes! it's $dataType | ||
``` | ||
|
||
Berikut adalah beberapa tipe nilai yang wajib ada. | ||
|
||
- Integer | ||
- String | ||
- Boolean | ||
- Double | ||
- List | ||
- Map | ||
|
||
#### Contoh 1: | ||
|
||
- Masukan: `args` = `10` | ||
- Keluaran: `Yes! it's Integer` | ||
- Penjelasan: Tipe data dari `10` adalah `Integer`. | ||
|
||
#### Contoh 2: | ||
|
||
- Masukan: `args` = `listOf("A", "B")` | ||
- Keluaran: `Yes! it's List` | ||
- Penjelasan: Tipe data dari `listOf("A", "B")` adalah `List`. | ||
|
||
#### Contoh 3: | ||
|
||
- Masukan: `args` = `true` | ||
- Keluaran: `Yes! it's Boolean` | ||
- Penjelasan: Tipe data dari `true` adalah `Boolean`. | ||
|
||
## Menguji Kode | ||
|
||
Untuk menguji kode, silakan jalankan fungsi `main` pada file `Exam3Main.kt`. | ||
|
||
Jika kode pada `Exam3.kt` sudah diperbaiki sesuai ketentuan, maka keluarannya akan seperti berikut: | ||
|
||
``` | ||
'Dicoding Indonesia' is String? Yes! it's String | ||
'True' is Boolean? Yes! it's Boolean | ||
'1' is Integer? Yes! it's Integer | ||
'10.01' is Double? Yes! it's Double | ||
'[10, 9, 8 , 6]' is List? Yes! it's List | ||
'{score=10}' is Map? Yes! it's Map | ||
``` |
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,4 @@ | ||
package com.dicoding.exam.exam4 | ||
|
||
// TODO | ||
fun vehicle() = Any() |
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,10 @@ | ||
package com.dicoding.exam.exam4 | ||
|
||
private fun main() { | ||
println( | ||
""" | ||
My Map Result: | ||
${vehicle()} | ||
""".trimIndent() | ||
) | ||
} |
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,45 @@ | ||
# Exam 4 - Collections | ||
|
||
## Ketentuan | ||
|
||
**Agar dapat diperiksa dengan baik, hindari beberapa hal berikut:** | ||
|
||
1. Mengubah kode fungsi `main()` yang berada di dalam file `Exam4Main.kt` | ||
2. Menghapus atau mengubah nama fungsi dan variable yang sudah ada di dalam file `Exam4.kt` | ||
3. Membuat fungsi baru yang bukan merupakan tugas latihan | ||
4. Mengubah struktur project (menghapus, mengedit, dan memindahkan package) | ||
|
||
## Instruksi | ||
|
||
Untuk mengerjakan soal latihan ini, silakan buka file `Exam4.kt`. | ||
|
||
### TODO | ||
|
||
Lengkapi inisialisasi fungsi `vehicle()` dengan tipe kembalian `Map` yang bernilai key-value berikut: | ||
|
||
- `key`: `type` | ||
- `value`: `motorcycle` | ||
|
||
|
||
- `key`: `maxSpeed` | ||
- `value`: `230Km/s` | ||
|
||
|
||
- `key`: `maxTank` | ||
- `value`: `100Ltr` | ||
|
||
#### Contoh : | ||
|
||
- Masukan: - | ||
- Keluaran: `{type=motorcycle, maxSpeed=230Km/s, maxTank=100Ltr}` | ||
|
||
## Menguji Kode | ||
|
||
Untuk menguji kode, silakan jalankan fungsi `main` pada file `Exam4Main.kt`. | ||
|
||
Jika kode pada `Exam4.kt` sudah diperbaiki sesuai ketentuan, maka keluarannya akan seperti berikut: | ||
|
||
``` | ||
My Map Result: | ||
{type=motorcycle, maxSpeed=230Km/s, maxTank=100Ltr} | ||
``` |
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,11 @@ | ||
package com.dicoding.exam.exam5 | ||
|
||
// TODO 1 | ||
fun sum(valueA: Int, valueB: Int): Int { | ||
return 0 | ||
} | ||
|
||
// TODO 2 | ||
fun multiple(valueA: Int, valueB: Int): Int { | ||
return 0 | ||
} |
Oops, something went wrong.