Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Eget_Projekt
  5. {
  6. class Program
  7. {
  8.  
  9.  
  10.  
  11.  
  12.  
  13. static void timeAndDate() //Metod för datum och tid.
  14. {
  15. DateTime time = DateTime.Now; //Hämtar datum och tid.
  16. Console.WriteLine("\n\tDate and time: " + time); //Skriver ut datum och tid.
  17. }
  18. static void introMenu() //Metod för intro texten när man startar programmet.
  19. {
  20. Console.Write("\n\t|--------------------------------------------------|");
  21. Console.WriteLine("\n\t\tWelcome to my little project." +
  22. "\n\t\tThis program will work as a diary." +
  23. "\n\t\tPlease, choose an option to continue.");
  24. Console.Write("\n\t|--------------------------------------------------|");
  25. }
  26. static void mainMenu() //Metod för huvudmenyn som innehåller alla valen.
  27. {
  28. //Valde att skriva programmet på engelska då flera
  29. Console.WriteLine("\n\t[1] Make a new entry." + //användare kan använda programmet.
  30. "\n\t[2] Print out all entries." +
  31. "\n\t[3] Print out all titles." +
  32. "\n\t[4] Search for previous entries." +
  33. "\n\t[5] Search for previous titles." +
  34. "\n\t[6] Remove an existing entry." +
  35. "\n\t[7] Exit program.");
  36. }
  37. static void Main(string[] args)
  38. {
  39. Console.BackgroundColor = ConsoleColor.DarkRed;
  40. Console.Clear();
  41.  
  42. List<string> entries = new List<string>(); //Lista för att hålla reda på inlägg.
  43. List<string> titles = new List<string>(); //Lista för att hålla reda på titlar.
  44. List<string[]> choice = new List<string[]>(); //Lista med sträng variabel kombinerad med en array.
  45. string[] post = new string[2];
  46. post[0] = "Title";
  47. post[1] = "Entry";
  48.  
  49. timeAndDate(); //Anropar min metod som innehåller tid och datum.
  50. introMenu(); //Anropar min metod som innehåller intro texten.
  51.  
  52. bool isRunning = true;
  53.  
  54. while (isRunning)
  55. {
  56. mainMenu(); //Anropar min metod som innehåller huvudmenyn.
  57.  
  58. int nr; //Standard int variabel.
  59. int.TryParse(Console.ReadLine(), out nr); //Felhantering av variabel.
  60.  
  61. switch (nr) //Switch sats som innehåller "nr" variabeln som är definierad ovanför.
  62. {
  63. case 1:
  64. Console.Write("\n\tEnter a title for your new entry: "); //Case för att spara titel och huvudtext.
  65. titles.Add(Console.ReadLine()); //Använder .ReadLine för att lägga till i listan.
  66. Console.Write("\n\tWrite an entry: ");
  67. entries.Add(Console.ReadLine());
  68. break;
  69.  
  70. case 2:
  71. Console.WriteLine("\n\tEntries that are currently saved: "); //Case för att skriva ut tidigare sparade huvudtexter.
  72. for (int i = 0; i < entries.Count; i++) //for-loop för att skriva ut sparade inputs i "entries".
  73. {
  74. Console.WriteLine("\t " + entries[i]);
  75. Console.ReadKey();
  76. }
  77. break;
  78.  
  79. case 3:
  80. Console.WriteLine("\n\tTitles that are currently saved: "); //Case för att skriva ut tidigare sparade titlar.
  81. for (int i = 0; i < titles.Count; i++) //for-loop för att skriva ut sparade inputs i "titles".
  82. {
  83. Console.WriteLine("\t " + titles[i]);
  84. Console.ReadKey();
  85. }
  86. break;
  87.  
  88. case 4:
  89. Console.Write("\tEntry search: "); //Case för att söka efter huvudtexter.
  90. string entrySearch = Console.ReadLine();
  91. bool entryFound = true; //bool-variabel för att kolla efter true/false.
  92.  
  93. for (int i = 0; i < entries.Count; i++)
  94. {
  95. if (entries[i].ToUpper().Contains(entrySearch.ToUpper())) //Använder .Contains för att kunna leta efter specifika texter.
  96. {
  97. Console.WriteLine("\tThis is what I could find: " + entries[i]);
  98. entryFound = false; //Om texten finns så blir "entryFound" false och man skippar if-satsen.
  99. Console.Write("\tPress any key to return to main menu.");
  100. Console.ReadKey();
  101. }
  102. }
  103.  
  104. if (entryFound == true) //if-sats som aktiveras om "entryFound" fortfarande är true.
  105. {
  106. Console.WriteLine("\tI could not find what you were looking for.");
  107. Console.Write("\tPress any key to return to main menu."); //Text som visas om man inte skulle hitta något via sökfunktionen.
  108. Console.ReadKey();
  109. }
  110. break;
  111.  
  112. case 5:
  113. Console.Write("\tTitle search: "); //Case för att söka efter titlar.
  114. string titleSearch = Console.ReadLine();
  115. bool titleFound = true; //bool-variabel för att kolla efter true/false.
  116.  
  117. for (int i = 0; i < titles.Count; i++) //Allting är identiskt till case 4 förutom att
  118. { //entry/entries är title/titles.
  119. if (titles[i].ToUpper().Contains(titleSearch.ToUpper()))
  120. {
  121. Console.WriteLine("\tThis is what I could find: " + titles[i]);
  122. titleFound = false;
  123. Console.Write("\tPress any key to return to main menu.");
  124. Console.ReadKey();
  125. }
  126. }
  127.  
  128. if (titleFound == true)
  129. {
  130. Console.WriteLine("\tI could not find what you wre looking for.");
  131. Console.Write("\tPress any key to return to main menu.");
  132. Console.ReadKey();
  133. }
  134. break;
  135.  
  136. case 6:
  137. {
  138. break;
  139. }
  140.  
  141. case 7:
  142. {
  143. Console.WriteLine("\n\tThank you for using my program, have a nice day!");
  144. isRunning = false;
  145. break;
  146. }
  147.  
  148. default:
  149. break;
  150. }
  151. }
  152.  
  153. Console.ReadLine();
  154.  
  155. }
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement