From a53ceb2def59b85b36185185a55ae338393b5c0c Mon Sep 17 00:00:00 2001 From: Hion-V Date: Thu, 2 Feb 2023 10:26:01 +0100 Subject: [PATCH] Opdracht 3c --- .../OOP-Opdracht-CSharp-Alfa-2022/Program.cs | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/Program.cs b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/Program.cs index aab57cf..f3ecb9e 100644 --- a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/Program.cs +++ b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/Program.cs @@ -11,15 +11,15 @@ namespace OOP_Opdracht_CSharp_Alfa_2022 Console.WriteLine("Hello World!"); Opdracht2(); Opdracht3(); + Opdracht3c(); } static void Opdracht2() { Game game = new classes.Game("game"); // Init publisher class instance var someRecord = game.find(1); // find specific record Console.WriteLine($"Record 1 is equal to {someRecord}"); - // Get the full dictionary and loop over each record - var games = game.getTableData(); + Dictionary games = game.getTableData(); Console.WriteLine("Outputting Table Contents:"); foreach (KeyValuePair entry in games) { @@ -42,5 +42,37 @@ namespace OOP_Opdracht_CSharp_Alfa_2022 } Console.WriteLine($"Trying to fetch KeyValue with invalid id 5 {publisher.find(7)}"); // Attempt to find invalid record and output to Console } + + + static void Opdracht3c() + { + Publisher publisher = new Publisher("publisher"); // Init publisher class instance + Dictionary tableDict = new Dictionary(); + + + while(true){ + String input; + // Ask user if they want to request a specific entry + Console.WriteLine("Would you like to look up a record? [Y/n]"); + input = Console.ReadLine(); + // Allow user to escape the loop + if(input == "n" || input == "N" || input == "no" || input == "NO" || input == "q"){ + break; + } + Console.WriteLine("Please enter the id of the publisher you wish to look up"); + input = Console.ReadLine(); + int id = -1; + try{ + id = int.Parse(input); + } + catch (FormatException) + { + Console.WriteLine("Invalid input for id. Please enter a positive Integer value (Whole number)"); + } + if(id >= 0){ + Console.WriteLine($"Record {id} is equal to {publisher.find(id)}"); + } + } + } } }