diff --git a/FunctionExercise/FunctionExercise.iml b/FunctionExercise/FunctionExercise.iml new file mode 100644 index 0000000..4fd7bdb --- /dev/null +++ b/FunctionExercise/FunctionExercise.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FunctionExercise/src/CamelRide.kt b/FunctionExercise/src/CamelRide.kt new file mode 100644 index 0000000..21dcd66 --- /dev/null +++ b/FunctionExercise/src/CamelRide.kt @@ -0,0 +1,8 @@ +fun main() { + startCamelRide(10, 5) + startCamelRide(10) +} +fun startCamelRide(time: Int, speed: Int = 5) { + val distance = time * speed + println("Camel Ride: Distance = $distance km, Speed = $speed km/h, Time = $time hours") +} diff --git a/FunctionExercise/src/DesertTemperature.kt b/FunctionExercise/src/DesertTemperature.kt new file mode 100644 index 0000000..542e9b7 --- /dev/null +++ b/FunctionExercise/src/DesertTemperature.kt @@ -0,0 +1,8 @@ +fun currentTemperature(morningTemperature: Int, afternoonTemperature: Int): Int { + return (morningTemperature + afternoonTemperature) / 2 +} + +fun main() { + val averageTemp = currentTemperature(25, 40) + println("Average temperature: $averageTemp") +} diff --git a/FunctionExercise/src/Main.kt b/FunctionExercise/src/Main.kt new file mode 100644 index 0000000..7265465 --- /dev/null +++ b/FunctionExercise/src/Main.kt @@ -0,0 +1,14 @@ +//TIP To Run code, press or +// click the icon in the gutter. +fun main() { + val name = "Kotlin" + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + println("Hello, " + name + "!") + + for (i in 1..5) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + println("i = $i") + } +} \ No newline at end of file diff --git a/FunctionExercise/src/OasisCounter.kt b/FunctionExercise/src/OasisCounter.kt new file mode 100644 index 0000000..47ec4a3 --- /dev/null +++ b/FunctionExercise/src/OasisCounter.kt @@ -0,0 +1,8 @@ +fun findOasis(x: Int, y: Int): String { + return "Oasis found at coordinates ($x, $y)" +} + +fun main() { + val result = findOasis(10, 20) + println(result) +} \ No newline at end of file diff --git a/FunctionExercise/src/SandstormSurvival.kt b/FunctionExercise/src/SandstormSurvival.kt new file mode 100644 index 0000000..b239ba7 --- /dev/null +++ b/FunctionExercise/src/SandstormSurvival.kt @@ -0,0 +1,5 @@ +fun survivalChance(supplies: Int) = supplies * 10 + +fun main() { + println("Survival Chance: ${survivalChance(8)}") +} \ No newline at end of file diff --git a/FunctionExercise/src/TheDesertGreeting.kt b/FunctionExercise/src/TheDesertGreeting.kt new file mode 100644 index 0000000..8c31842 --- /dev/null +++ b/FunctionExercise/src/TheDesertGreeting.kt @@ -0,0 +1,6 @@ +fun main () { + greenTraveler() +} +fun greenTraveler () { + println("Welcome to the Desert, Traveler!") +} \ No newline at end of file diff --git a/FunctionExercise/src/TheDuneExploration.kt b/FunctionExercise/src/TheDuneExploration.kt new file mode 100644 index 0000000..f872576 --- /dev/null +++ b/FunctionExercise/src/TheDuneExploration.kt @@ -0,0 +1,8 @@ +fun exploreDune(height: Int, climbRate: Int) { + val time = height.toDouble() / climbRate + println("Time to Climb the Dune: $time hours") +} + +fun main() { + exploreDune(climbRate = 3, height = 20) +} \ No newline at end of file