Advertisement
Guest User

recipe_maker.kt

a guest
Jan 13th, 2021
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 4.44 KB | None | 0 0
  1.  
  2.  
  3. /*
  4. Recipe maker
  5.  
  6. Main idea:
  7.     + dislay menu with user options
  8.         +,i create recipe
  9.         +,i view recipes
  10.         +,i exit
  11.  
  12. To-do
  13.     + funs
  14.         +,i makeRecipe() --ipt[Str: recipe_name, Str: {Ingredients}]
  15.         +,i viewRecipes() --print recipes from userRecipes map
  16.         +,i showMenu() --display menu and options
  17.         +,i sleepText() --displat text and sleep for x time
  18.         +,i main() --call displat manu
  19.     + global vars
  20.         +,i var userRecipes() --Map<String, String>
  21.         +,i var ingredients() --list
  22.  
  23. */
  24.  
  25. const val time: Long = 50L
  26. var recipeCounter: Int = 0
  27. var userRecipes = mutableMapOf("Test recipe 1" to "soup, egg, oatmeal, meat")
  28. var serverIngredients = listOf(
  29.     "Water 💧",
  30.     "Milk 🥛",
  31.     "Meat 🥩",
  32.     "Vegetables 🥦",
  33.     "Fruits 🍎",
  34.     "Cereal 🥣",
  35.     "Eggs 🥚",
  36.     "Tomato 🍅",
  37.     "Pineapple 🍍",
  38.     "Pickle 🥒",
  39.     "Avocado 🥑",
  40.     "Oil 🛢",
  41.     "Cherry 🍒",
  42.     "Turtle 🐢"
  43. ) //list must be uneven number for it to work while printing
  44.  
  45. fun main() {
  46.  
  47.     showMenu()
  48. }
  49.  
  50. fun showMenu() {
  51.  
  52.     var response: Int = 0
  53.  
  54.     do {
  55.         print("🥞----RECIPE-CREATOR----🥞\n\n")
  56.  
  57.         sleepText(time, "1) Make Recipe ✍"); sleepText(time, "2) View Recipes 📋"); sleepText(time, "0) Exit ❌")
  58.         print("\nType here 👉 ")
  59.         response = Integer.valueOf(readLine())
  60.  
  61.         if (response == 0) {
  62.             break;
  63.         } else if (response == 1) {
  64.             makeRecipe()
  65.         } else if (response == 2) {
  66.             viewRecipes()
  67.         } else {
  68.             println("Sorry, the command $response was not recognized, please try again down below")
  69.             showMenu()
  70.         }
  71.  
  72.     } while(response != 0)
  73.  
  74. }
  75.  
  76. fun makeRecipe() {
  77.  
  78.     var recipeName: String?
  79.     var recipeIngredients: String?
  80.  
  81.     print("\n\tFirst of all, what is going to be the name of your recipe?: ")
  82.     recipeName = readLine() ?: "Default recipe name #$recipeCounter"
  83.  
  84.     println("\n")
  85.     // possibly add "are you sure?" part here
  86.     var n1: Int = 1
  87.     var n2: Int = 2
  88.     var runnedIndexes = mutableListOf(-1)
  89.     for((index, value) in serverIngredients.withIndex()) {
  90.         var indexN1: Int = index + n1
  91.         var indexN2: Int = index + n2
  92.  
  93.         if (serverIngredients.size / 2 == index) {
  94.             break
  95.         } else {
  96.  
  97.             if (index == 0) {
  98.                 sleepText(time, "\t$index) $value\t\t\t$indexN1) " + serverIngredients[indexN1])
  99.             } else {
  100.                 sleepText(time, "\t$indexN1) " + serverIngredients[index + n1] + "\t\t\t$indexN2) " + serverIngredients[index + n2])
  101.                 ++n1; ++n2;
  102.             }
  103.         }
  104.         // println("----$index-$indexPlusOne----")
  105.  
  106.         /*
  107.             0i  0 1     +0 +0
  108.             1i  2 3     +1 +2
  109.             2i  4 5     +2 +3
  110.             3i  6 7     +3 +4
  111.             4i  8 9     +4 +5
  112.             5i  10 11   +5 +6
  113.          */
  114.     }
  115.  
  116.     print("\n\tChoose all the ingredients you want from the above list (type them here): ")
  117.     recipeIngredients = readLine() ?: "None"
  118.  
  119.  
  120.     do {
  121.         print("\tConfirm your recipe [y/n]: ")
  122.         print("Type here 👉 ")
  123.         var response: String? = readLine()
  124.  
  125.         if (response.equals("yes") || response.equals("y")) {
  126.             userRecipes.put("$recipeName", "$recipeIngredients")
  127.  
  128.             println("\n\t------------------------------------------------\n\tGreat, your recipe has been added successfully! 😁\n\t------------------------------------------------\n")
  129.             ++recipeCounter;
  130.             break;
  131.         } else if (response.equals("no") || response.equals("n")) {
  132.             println("Okay then! let's try again..."); makeRecipe(); break
  133.         } else {
  134.             println("You typed '$response', you must type either 'yes' or 'no'"); Thread.sleep(1000L)
  135.         }
  136.     } while (!response.equals("yes") || !response.equals("y"))
  137.  
  138. }
  139.  
  140. fun sleepText(time: Long, str: String) {
  141.     println(str); Thread.sleep(time)
  142. }
  143.  
  144. fun viewRecipes() {
  145.     if (userRecipes.isEmpty()) {
  146.         println("Ups... It seems that there are no recipes in here! why not create a new one shall we?")
  147.     } else {
  148.         var index: Byte = 1
  149.         for ((key, value) in userRecipes) {
  150.             print("--------------------\n🔷 #$index\n\tRecipe Name: $key:\n\tIngredients: $value\n------------------------\n\n")
  151.             ++index
  152.         }
  153.     }
  154. }
  155.  
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement