Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace EX01___Opgave_2
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool done = false;
- string keuze = null;
- Boek oBoek;
- List<Boek> boekenLijst = new List<Boek>();
- List<string> genreLijst = new List<string>();
- Console.Write("Hoeveel genres wil je invoeren: ");
- int aantal = Convert.ToInt32(Console.ReadLine());
- for (int i = 1; i - 1 < aantal; i++)
- {
- oBoek = new Boek();
- Console.Write("Genre " + i + ": ");
- oBoek.Genre = Console.ReadLine();
- genreLijst.Add(oBoek.Genre);
- }
- do
- {
- Console.WriteLine("\nMenu:");
- Console.WriteLine("1. Boek toevoegen");
- Console.WriteLine("2. Boeken weergeven");
- Console.WriteLine("3. Titel boek wijzigen");
- Console.WriteLine("4. Boek verwijderen");
- Console.WriteLine("5. Boek op genre zoeken");
- Console.WriteLine("6. Boek op prijs zoeken");
- Console.WriteLine("0. Einde");
- Console.Write("Maak je keuze: ");
- keuze = Console.ReadLine();
- // Keuze 1
- if (keuze == "1")
- {
- oBoek = new Boek();
- Console.WriteLine("\nBoek toevoegen:");
- Console.Write("Auteur: ");
- oBoek.Auteur = Console.ReadLine();
- Console.Write("Titel: ");
- oBoek.Titel = Console.ReadLine();
- Console.Write("Prijs (in euro): ");
- oBoek.Prijs = Convert.ToDouble(Console.ReadLine());
- Console.Write("Releasedatum (dd/mm/jjjj): ");
- oBoek.ReleaseDatum = Convert.ToDateTime(Console.ReadLine());
- Console.WriteLine("Mogelijke genres:");
- for (int i = 0; i < aantal; i++)
- {
- Console.Write(genreLijst[i] + "/");
- }
- Console.Write("\n");
- do
- {
- Console.Write("Genre: ");
- oBoek.Genre = Console.ReadLine();
- if (genreLijst.Contains(oBoek.Genre))
- {
- done = true;
- }
- else
- {
- Console.WriteLine("Genre " + oBoek.Genre + " is niet gekend.");
- }
- } while (done == false);
- done = false;
- boekenLijst.Add(oBoek);
- Console.WriteLine("het boek " + oBoek + " is toegevoegd aan de lijst.");
- }
- // Keuze 2
- if (keuze == "2")
- {
- Console.WriteLine("\nBoeken weergeven:");
- for (int i = 1; i - 1 < boekenLijst.Count; i++)
- {
- oBoek = boekenLijst[i - 1];
- Console.WriteLine(i + ". " + oBoek);
- }
- }
- // Keuze 3
- if (keuze == "3")
- {
- Console.WriteLine("\nTitel boek wijzigen:");
- for (int i = 1; i - 1 < boekenLijst.Count; i++)
- {
- oBoek = boekenLijst[i - 1];
- Console.WriteLine(i + ". " + oBoek);
- }
- Console.Write("Kies je boek: ");
- int wijzigBoek = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Vorige titel: " + boekenLijst[wijzigBoek - 1]);
- Console.Write("Nieuwe titel? ");
- string nieuwtitel = Console.ReadLine();
- boekenLijst[wijzigBoek - 1].Titel = nieuwtitel;
- }
- // Keuze 4
- if (keuze == "4")
- {
- Console.WriteLine("\nBoek verwijderen:");
- for (int i = 1; i - 1 < boekenLijst.Count; i++)
- {
- oBoek = boekenLijst[i - 1];
- Console.WriteLine(i + ". " + oBoek);
- }
- Console.Write("Kies je boek: ");
- int verwijderBoek = Convert.ToInt32(Console.ReadLine());
- if (boekenLijst.Count() > verwijderBoek)
- {
- boekenLijst.RemoveAt(verwijderBoek - 1);
- } else
- {
- Console.WriteLine("Volgnummer " + verwijderBoek + " bestaat niet.");
- }
- }
- // Keuze 5
- if (keuze == "5")
- {
- Console.WriteLine("\nBoek op genre zoeken:");
- Console.Write("Geef het genre waar je op wilt zoeken: ");
- string zoekGenre = Console.ReadLine();
- for (int i = 1; i - 1 < boekenLijst.Count; i++)
- {
- oBoek = boekenLijst[i - 1];
- if (oBoek.Genre == zoekGenre)
- {
- Console.WriteLine(i + ". " + oBoek);
- }
- }
- }
- // Keuze 6
- if (keuze == "6")
- {
- Console.WriteLine("Boek op prijs zoeken: ");
- Console.WriteLine("Zoeken tussen ...");
- Console.Write("Laagste prijs: ");
- double lprijs = Convert.ToDouble(Console.ReadLine());
- Console.Write("Hoogste prijs: ");
- double hprijs = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Boeken tussen " + lprijs + " en " + hprijs + " euro:");
- for (int i = 1; i - 1 < boekenLijst.Count; i++)
- {
- oBoek = boekenLijst[i - 1];
- if (oBoek.Prijs > lprijs && oBoek.Prijs < hprijs)
- {
- Console.WriteLine(i + ". " + oBoek);
- Console.WriteLine("Prijs van dit boek: " + oBoek.Prijs + " euro");
- }
- }
- }
- } while (keuze != "0");
- Console.WriteLine("\nDruk een toets...");
- }
- }
- }
- // CLASS
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace EX01___Opgave_2
- {
- class Boek
- {
- public string Auteur { get; set; }
- public string Titel { get; set; }
- public double Prijs { get; set; }
- public DateTime ReleaseDatum { get; set; }
- public string Genre { get; set; }
- public override string ToString()
- {
- return Titel + " (" + Auteur + ")";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement