Skip to content

Instantly share code, notes, and snippets.

@renatojobal
Created April 19, 2020 15:23
Show Gist options
  • Save renatojobal/59c2767760bfcfc8968eff0dc64c78c7 to your computer and use it in GitHub Desktop.
Save renatojobal/59c2767760bfcfc8968eff0dc64c78c7 to your computer and use it in GitHub Desktop.
// Recipes Maker
fun main(args: Array<String>) {
principalProcess@while (true) {
val menuChoice: Int = getMenuChoice()
if (menuChoice.equals(1)) {
println("""You choice make a recipe""")
makeRecipe()
} else if (menuChoice.equals(2)) {
println("You choice see your recipes")
} else if (menuChoice == 3) {
println("Bye bye")
break@principalProcess
}
}
}
fun makeRecipe(){
val selectedIngredients : List<String> = getIngredients()
println("""
The ingredients selected are:
$selectedIngredients
""".trimIndent())
}
fun getMenuChoice() : Int {
val menu = """
:: Welcome to Recipe Maker ::
Select from the following options
1. Create a recipe
2. Vie my recipes
3. Exit
""".trimIndent()
println(menu)
val response: String = readLine()?: "0"
return response.toInt()
}
fun getIngredients() : List<String> {
val ingredientList: List<String>? = listOf(
"1= ","Water",
"2= ","Milk",
"3= ","Meat",
"4= ","Vegetables",
"5= ","Fruits",
"6= ","Cereal",
"7= ","Egg",
"8= ","Oil",
"0= ","Exit-->"
)
var targetIngredients: ArrayList<String> = arrayListOf<String>()
choosingIngredients@while (true){
println("""Ingredients:
$ingredientList
""".trimMargin())
val choice: Int? = readLine()?.toInt() ?: 0
var targetIngredient: String
if(choice == 0){
break@choosingIngredients
}else if(choice == 1){
targetIngredient = ingredientList!!.get(1)
}else{
targetIngredient = ingredientList!!.get(choice!!.times(2).minus(1))
}
targetIngredients.add(targetIngredient)
println("Added ingredient\n")
}
return targetIngredients
}
@renatojobal
Copy link
Author

Program from a challenge in the course of Kotlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment