Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 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.  
  19. static void introMenu() //Metod för intro texten när man startar programmet.
  20. {
  21. Console.Write("\n\t|--------------------------------------------------|");
  22. Console.WriteLine("\n\t\tWelcome to my little project." +
  23. "\n\t\tThis program will work as a diary." +
  24. "\n\t\tPlease, choose an option to continue.");
  25. Console.Write("\n\t|--------------------------------------------------|");
  26. }
  27. static void mainMenu() //Metod för huvudmenyn som innehåller alla valen.
  28. {
  29. //Valde att skriva programmet på engelska då flera
  30. Console.WriteLine("\n\t[1] Make a new entry." + //användare kan använda programmet.
  31. "\n\t[2] Print out all entries." +
  32. "\n\t[3] Print out all titles." +
  33. "\n\t[4] Search for previous entries." +
  34. "\n\t[5] Search for previous titles." +
  35. "\n\t[6] Remove an existing entry." +
  36. "\n\t[7] Exit program.");
  37. }
  38.  
  39. static void Main(string[] args)
  40. {
  41. Console.BackgroundColor = ConsoleColor.DarkRed;
  42. Console.Clear();
  43.  
  44. List<string> entries = new List<string>(); //Lista för att hålla reda på inlägg.
  45. List<string> titles = new List<string>(); //Lista för att hålla reda på titlar.
  46. List<string[]> choice = new List<string[]>(); //Lista med sträng variabel kombinerad med en array.
  47. string[] post = new string[2];
  48. post[0] = "Title";
  49. post[1] = "Entry";
  50.  
  51. timeAndDate(); //Anropar min metod som innehåller tid och datum.
  52. introMenu(); //Anropar min metod som innehåller intro texten.
  53.  
  54. bool isRunning = true;
  55.  
  56. while (isRunning)
  57. {
  58. mainMenu(); //Anropar min metod som innehåller huvudmenyn.
  59.  
  60. int nr; //Standard int variabel.
  61. int.TryParse(Console.ReadLine(), out nr); //Felhantering av variabel.
  62.  
  63. switch (nr) //Switch sats som innehåller "nr" variabeln som är definierad ovanför.
  64. {
  65. case 1:
  66. Console.Write("\n\tEnter a title for your new entry: ");
  67. titles.Add(Console.ReadLine());
  68. Console.Write("\n\tWrite an entry: ");
  69. entries.Add(Console.ReadLine());
  70. break;
  71.  
  72. case 2:
  73. Console.WriteLine("\n\tEntries that are currently saved: ");
  74. for (int i = 0; i < entries.Count; i++)
  75. {
  76. Console.WriteLine("\t " + entries[i]);
  77. Console.ReadKey();
  78. }
  79. break;
  80.  
  81. case 3:
  82. Console.WriteLine("\n\tTitles that are currently saved: ");
  83. for (int i = 0; i < titles.Count; i++)
  84. {
  85. Console.WriteLine("\t " + titles[i]);
  86. Console.ReadKey();
  87. }
  88. break;
  89.  
  90. case 4:
  91. Console.Write("\tEntry search: ");
  92. string entrySearch = Console.ReadLine();
  93. bool entryFound = true;
  94.  
  95. for (int i = 0; i < entries.Count; i++)
  96. {
  97. if (entries[i].ToUpper().Contains(entrySearch.ToUpper()))
  98. {
  99. Console.WriteLine("\tThis is what I could find: " + entries[i]);
  100. entryFound = false;
  101. Console.Write("\tPress any key to return to main menu.");
  102. Console.ReadKey();
  103. }
  104. }
  105.  
  106. if (entryFound == true)
  107. {
  108. Console.WriteLine("\tI could not find what you were looking for.");
  109. Console.Write("\tPress any key to return to main menu.");
  110. Console.ReadKey();
  111. }
  112. break;
  113.  
  114. case 5:
  115. Console.Write("\tTitle search: ");
  116. string titleSearch = Console.ReadLine();
  117. bool titleFound = true;
  118.  
  119. for (int i = 0; i < titles.Count; i++)
  120. {
  121. if (titles[i].ToUpper().Contains(titleSearch.ToUpper()))
  122. {
  123. Console.WriteLine("\tThis is what I could find: " + titles[i]);
  124. titleFound = false;
  125. Console.Write("\tPress any key to return to main menu.");
  126. Console.ReadKey();
  127. }
  128. }
  129.  
  130. if (titleFound == true)
  131. {
  132. Console.WriteLine("\tI could not find what you wre looking for.");
  133. Console.Write("\tPress any key to return to main menu.");
  134. Console.ReadKey();
  135. }
  136. break;
  137.  
  138. default:
  139. break;
  140. }
  141. }
  142. }
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement