Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace EX01___Opgave_2
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. bool done = false;
  12. string keuze = null;
  13.  
  14. Boek oBoek;
  15. List<Boek> boekenLijst = new List<Boek>();
  16. List<string> genreLijst = new List<string>();
  17.  
  18. Console.Write("Hoeveel genres wil je invoeren: ");
  19. int aantal = Convert.ToInt32(Console.ReadLine());
  20.  
  21. for (int i = 1; i - 1 < aantal; i++)
  22. {
  23. oBoek = new Boek();
  24. Console.Write("Genre " + i + ": ");
  25. oBoek.Genre = Console.ReadLine();
  26. genreLijst.Add(oBoek.Genre);
  27. }
  28.  
  29. do
  30. {
  31. Console.WriteLine("\nMenu:");
  32. Console.WriteLine("1. Boek toevoegen");
  33. Console.WriteLine("2. Boeken weergeven");
  34. Console.WriteLine("3. Titel boek wijzigen");
  35. Console.WriteLine("4. Boek verwijderen");
  36. Console.WriteLine("5. Boek op genre zoeken");
  37. Console.WriteLine("6. Boek op prijs zoeken");
  38. Console.WriteLine("0. Einde");
  39. Console.Write("Maak je keuze: ");
  40.  
  41. keuze = Console.ReadLine();
  42.  
  43. // Keuze 1
  44. if (keuze == "1")
  45. {
  46. oBoek = new Boek();
  47. Console.WriteLine("\nBoek toevoegen:");
  48. Console.Write("Auteur: ");
  49. oBoek.Auteur = Console.ReadLine();
  50. Console.Write("Titel: ");
  51. oBoek.Titel = Console.ReadLine();
  52. Console.Write("Prijs (in euro): ");
  53. oBoek.Prijs = Convert.ToDouble(Console.ReadLine());
  54. Console.Write("Releasedatum (dd/mm/jjjj): ");
  55. oBoek.ReleaseDatum = Convert.ToDateTime(Console.ReadLine());
  56. Console.WriteLine("Mogelijke genres:");
  57. for (int i = 0; i < aantal; i++)
  58. {
  59. Console.Write(genreLijst[i] + "/");
  60. }
  61. Console.Write("\n");
  62. do
  63. {
  64. Console.Write("Genre: ");
  65. oBoek.Genre = Console.ReadLine();
  66.  
  67. if (genreLijst.Contains(oBoek.Genre))
  68. {
  69. done = true;
  70. }
  71. else
  72. {
  73. Console.WriteLine("Genre " + oBoek.Genre + " is niet gekend.");
  74. }
  75. } while (done == false);
  76. done = false;
  77.  
  78. boekenLijst.Add(oBoek);
  79.  
  80. Console.WriteLine("het boek " + oBoek + " is toegevoegd aan de lijst.");
  81. }
  82.  
  83. // Keuze 2
  84. if (keuze == "2")
  85. {
  86. Console.WriteLine("\nBoeken weergeven:");
  87.  
  88. for (int i = 1; i - 1 < boekenLijst.Count; i++)
  89. {
  90. oBoek = boekenLijst[i - 1];
  91.  
  92. Console.WriteLine(i + ". " + oBoek);
  93. }
  94. }
  95.  
  96.  
  97. // Keuze 3
  98. if (keuze == "3")
  99. {
  100. Console.WriteLine("\nTitel boek wijzigen:");
  101. for (int i = 1; i - 1 < boekenLijst.Count; i++)
  102. {
  103. oBoek = boekenLijst[i - 1];
  104.  
  105. Console.WriteLine(i + ". " + oBoek);
  106. }
  107.  
  108. Console.Write("Kies je boek: ");
  109. int wijzigBoek = Convert.ToInt32(Console.ReadLine());
  110.  
  111. Console.WriteLine("Vorige titel: " + boekenLijst[wijzigBoek - 1]);
  112. Console.Write("Nieuwe titel? ");
  113. string nieuwtitel = Console.ReadLine();
  114.  
  115. boekenLijst[wijzigBoek - 1].Titel = nieuwtitel;
  116. }
  117.  
  118. // Keuze 4
  119. if (keuze == "4")
  120. {
  121. Console.WriteLine("\nBoek verwijderen:");
  122. for (int i = 1; i - 1 < boekenLijst.Count; i++)
  123. {
  124. oBoek = boekenLijst[i - 1];
  125.  
  126. Console.WriteLine(i + ". " + oBoek);
  127. }
  128. Console.Write("Kies je boek: ");
  129. int verwijderBoek = Convert.ToInt32(Console.ReadLine());
  130.  
  131. if (boekenLijst.Count() > verwijderBoek)
  132. {
  133. boekenLijst.RemoveAt(verwijderBoek - 1);
  134. } else
  135. {
  136. Console.WriteLine("Volgnummer " + verwijderBoek + " bestaat niet.");
  137. }
  138.  
  139. }
  140.  
  141. // Keuze 5
  142. if (keuze == "5")
  143. {
  144. Console.WriteLine("\nBoek op genre zoeken:");
  145. Console.Write("Geef het genre waar je op wilt zoeken: ");
  146. string zoekGenre = Console.ReadLine();
  147.  
  148. for (int i = 1; i - 1 < boekenLijst.Count; i++)
  149. {
  150. oBoek = boekenLijst[i - 1];
  151.  
  152. if (oBoek.Genre == zoekGenre)
  153. {
  154. Console.WriteLine(i + ". " + oBoek);
  155. }
  156. }
  157. }
  158.  
  159. // Keuze 6
  160. if (keuze == "6")
  161. {
  162. Console.WriteLine("Boek op prijs zoeken: ");
  163. Console.WriteLine("Zoeken tussen ...");
  164. Console.Write("Laagste prijs: ");
  165. double lprijs = Convert.ToDouble(Console.ReadLine());
  166. Console.Write("Hoogste prijs: ");
  167. double hprijs = Convert.ToDouble(Console.ReadLine());
  168. Console.WriteLine("Boeken tussen " + lprijs + " en " + hprijs + " euro:");
  169.  
  170. for (int i = 1; i - 1 < boekenLijst.Count; i++)
  171. {
  172. oBoek = boekenLijst[i - 1];
  173.  
  174. if (oBoek.Prijs > lprijs && oBoek.Prijs < hprijs)
  175. {
  176. Console.WriteLine(i + ". " + oBoek);
  177. Console.WriteLine("Prijs van dit boek: " + oBoek.Prijs + " euro");
  178. }
  179. }
  180. }
  181. } while (keuze != "0");
  182.  
  183. Console.WriteLine("\nDruk een toets...");
  184. }
  185. }
  186. }
  187.  
  188.  
  189.  
  190. // CLASS
  191.  
  192. using System;
  193. using System.Collections.Generic;
  194. using System.Text;
  195.  
  196. namespace EX01___Opgave_2
  197. {
  198. class Boek
  199. {
  200. public string Auteur { get; set; }
  201. public string Titel { get; set; }
  202. public double Prijs { get; set; }
  203. public DateTime ReleaseDatum { get; set; }
  204. public string Genre { get; set; }
  205.  
  206. public override string ToString()
  207. {
  208. return Titel + " (" + Auteur + ")";
  209. }
  210. }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement