static void Main(string[] args) { // PEDAC // // Problem: // I need a program that I can hold a list of dinosours. // // CRUD // Create: Add new dino // Read: Get lists of dino that are housed in enclosures // Update: Update a transfer/switch of enclosure numbers // Delete : remove dino from list // Data: // need a "Dino" class // need a list of the dinos // Algorithm: // // Welcome message? // // // Show a menu of options // // make new dino input // see all current dinos and current enclosed number area // input name of dino and change(transfer) enclosed number area // summary of carnivor dinos (number) // summary of herb dinos (number) // remove dino from list (find and delete) // quit program var dinos = new List <Dino>() { new Dino { Name = "BroRex", Diet = "Herbivore", WhenAcquired = DateTime.Now, Weight = "653", EnclosureNumber = 3, }, new Dino { Name = "Staggy", Diet = "Carnivore", WhenAcquired = DateTime.Now, Weight = "45621", EnclosureNumber = 1, }, new Dino { Name = "Bettyaurus", Diet = "Herbivore", WhenAcquired = DateTime.Now, Weight = "750", EnclosureNumber = 2, }, }; Console.WriteLine("--------------------"); Console.WriteLine("--------------------"); Console.WriteLine("--------------------"); Console.WriteLine("Hello World! Welcome to the Jurassic Park database"); Console.WriteLine("--------------------"); Console.WriteLine("--------------------"); Console.WriteLine("--------------------"); var quitApplication = false; while (quitApplication == false) { Console.WriteLine("What would you like to do today?"); Console.WriteLine("ADD - Input new data on a new Dino"); Console.WriteLine("VIEW - Look-up Dino data and where you can see them"); Console.WriteLine("REMOVE - Delete a Dino from our database"); Console.WriteLine("TRANSFER - Update Dino Enclosure number"); Console.WriteLine("SUMMARY - Display a summary of specific Dino data"); Console.WriteLine("QUIT - Exit the Dino database"); Console.WriteLine(); Console.Write("Choice: "); var choice = Console.ReadLine(); if (choice.ToUpper() == "QUIT") { quitApplication = true; } if (choice.ToUpper() == "ADD") { Console.Write("Name: "); var name = Console.ReadLine(); Console.Write("Diet (Carnivore or Herbivore): "); var diet = Console.ReadLine(); var whenAcquired = DateTime.Now; Console.WriteLine($"When added to database: {whenAcquired}"); Console.Write("Weight: "); var weight = Console.ReadLine(); Console.Write("Enclosure Number: "); var enclosureNumberString = Console.ReadLine(); var enclosurenumber = int.Parse(enclosureNumberString); var dino = new Dino() { Name = name, Diet = diet, WhenAcquired = DateTime.Now, Weight = weight, EnclosureNumber = enclosurenumber, }; dinos.Add(dino); } if (choice.ToUpper() == "VIEW") { foreach (var dino in dinos) { Console.WriteLine(dino.Description()); } } if (choice.ToUpper() == "REMOVE") { var foundDino = PromptAndFindDino(dinos); if (foundDino != null) { Console.WriteLine(foundDino.Description()); Console.Write("Are you sure you want to delete a deceased Dino, YES or NO: "); var answer = Console.ReadLine(); if (answer.ToUpper() == "YES") { dinos.Remove(foundDino); } } else { Console.WriteLine($"There is no Dino to delete"); } } if (choice.ToUpper() == "TRANSFER") { var foundDino = PromptAndFindDino(dinos); if (foundDino != null) { Console.WriteLine(foundDino.Description()); Console.Write("Are you sure you want to transfer this Dino, YES or NO: "); var answer = Console.ReadLine(); if (answer.ToUpper() == "YES") { Console.Write("New Enclosure Number: "); var newEnclosureNumber = Console.ReadLine(); foundDino.EnclosureNumber = int.Parse(newEnclosureNumber); } else { Console.WriteLine($"There is no Dino found"); } } } if (choice.ToUpper() == "SUMMARY") { } Console.WriteLine("Have a great day!"); } }
static void Main(string[] args) { Greeting(); // Next we are going to create a List to store all the Dino information that we are going to obtain from the prompting statements we will be creating later. var dinoList = new List <Dino>(); var keepGoing = true; // Then we are going to create a boolean statement to run a “While” loop for our program. while (keepGoing) { // Next we're going to be asking the user if they wish to [V]iew, [A]dd, [R]emove, [T]ransfer, Diet [S]ummary, or [Quit] by creating a simple menu prompt. Console.WriteLine(); Console.Write("What do you want to do? [V]iew, [D]escription [A]dd, [R]emove, [T]ransfer, [S]ummary of Diet, or [Q]uit ? "); var choice = Console.ReadLine().ToUpper(); Console.WriteLine(); // IF QUIT if (choice == "Q") { keepGoing = false; Console.WriteLine("Exiting Database.... GOODBYE :)"); } // IF REMOVE else if (choice == "R") { var name = PromptForString("Who do you want to Remove?: ").ToUpper(); var foundDino = dinoList.FirstOrDefault(dino => dino.Name == name); if (foundDino == null) { Console.WriteLine("I can't find that Dinosaur to delete!"); } else { dinoList.Remove(foundDino); Console.WriteLine($"{name} has been Removed!"); } } // IF TRANSFER else if (choice == "T") { var name = PromptForString("Which Dinosaur do you wish to Transfer? ").ToUpper(); int index = dinoList.FindIndex(dino => name == dino.Name); if (index == -1) { Console.WriteLine($"Could not find '{name}' in the records!"); } else { var newEnclosure = PromptForInteger($"What Enclosure Number do you want to transfer {name} to? "); dinoList[index].EnclosureNumber = newEnclosure; Console.WriteLine($"Transfering {name} to Enclosure Number:{newEnclosure} .... DONE!"); } } // IF DESCRIPTION else if (choice == "D") { if (dinoList.Count > 0) { foreach (var dino in dinoList) { Console.WriteLine(dino.Description()); } } } // IF SUMMARY else if (choice == "S") { var carns = 0; var herbs = 0; foreach (var dino in dinoList) { if (dino.DietType == "carnivore") { carns++; } else if (dino.DietType == "herbivore") { herbs++; } } Console.WriteLine($"There are {carns} Carnivores and {herbs} Herbivores."); } // IF VIEW else if (choice == "V") { Console.WriteLine("Would you like to View [A]LL or by [D]ATE added? "); var answer = Console.ReadLine().ToUpper(); if (answer == "A") { foreach (var saur in dinoList) { Console.WriteLine(saur.Name); } } else if (answer == "D") { foreach (var saur in dinoList) { var WhenAcquired = dinoList.OrderBy(dinosaur => dinosaur.WhenAcquired); Console.WriteLine(saur.Name); Console.WriteLine(saur.WhenAcquired); } } } //IF ADD else { var dino = new Dino(); dino.Name = PromptForString("What is the Dinosaur's name? ").ToUpper(); dino.DietType = PromptForString("What is the Dinosaur's diet type: [Carnivore/Herbivore]? ").ToUpper(); dino.WhenAcquired = DateTime.Now; dino.Weight = PromptForInteger("What is the Dinosaur's weight [in pounds]? "); dino.EnclosureNumber = PromptForInteger("What is the Dinosaur's enclosure number?"); Console.WriteLine(); Console.WriteLine($"The new Dinosaur -{dino.Name}- will be added to the Database!"); Console.WriteLine(); dinoList.Add(dino); } } }
static void Main(string[] args) { // Starting The Program // |||||||||||||||||||| // |||||||||||||||||||| Console.Clear(); Console.WriteLine("Hello, welcome to Caveman's High Tech Dinosaur Tracker!"); Console.WriteLine("Modern Solutions for Prehistoric Problems"); var runTime = true; var zooDinosaurs = new List <Dinosaur>(); // Adding Dummy Data // ||||||||||||||||| zooDinosaurs.Add(new Dinosaur() { name = "Veloceraptor", dietType = "Carnivorous", whenAcquired = DateTime.Now.AddMonths(-1), weight = 33, enclosureNumber = 1, iD = 001, }); zooDinosaurs.Add(new Dinosaur() { name = "Veloceraptor", dietType = "Carnivorous", whenAcquired = DateTime.Now.AddMonths(-2), weight = 34, enclosureNumber = 1, iD = 002, }); zooDinosaurs.Add(new Dinosaur() { name = "Brontosaurus", dietType = "Herbivorous", whenAcquired = DateTime.Now.AddMonths(-6), weight = 36000, enclosureNumber = 5, iD = 003, }); zooDinosaurs.Add(new Dinosaur() { name = "Stegosaurus", dietType = "Herbivorous", whenAcquired = DateTime.Now.AddMonths(-3), weight = 6800, enclosureNumber = 5, iD = 004, }); // --------Menu---------- // |||||||||||||||||||||| while (runTime == true) { Console.WriteLine("--View-- Show all the Dinosaurs currently in Zoo and their current state."); Console.WriteLine("--ADD-- Add a new Dinosaur brought into the Zoo into the CHTDT Management System"); Console.WriteLine("--Transfer-- Change a Dinosaur's listed Enclosure"); Console.WriteLine("--Remove-- Remove a Dinosaur from the CHTDT Management System "); Console.WriteLine("--Summary-- Shows the current number of Carnivores & Herbivores at the Zoo"); Console.WriteLine("--Quit-- Exit out of the CHTDT Management System"); string choice = Console.ReadLine().ToUpper(); Console.Clear(); if (choice != "VIEW" && choice != "ADD" && choice != "REMOVE" && choice != "TRANSFER" && choice != "SUMMARY" && choice != "QUIT") { choice = "FALSE"; } switch (choice) { // ----View Option---- // ||||||||||||||||||| case "VIEW": var dinosInOrder = zooDinosaurs.OrderBy(Dinosaurs => Dinosaurs.whenAcquired); foreach (Dinosaur Dino in dinosInOrder) { Dino.PrintDescription(); Console.WriteLine("\r\n"); } break; // ----Add Option---- // |||||||||||||||||| case "ADD": int tempiD = zooDinosaurs.Max(Dinosaurs => Dinosaurs.iD) + 1; Console.WriteLine($"Adding new Dinosaur. His Unique ID will be {tempiD}."); Console.WriteLine("Please give the Dinosaurs Species' name?"); string tempName = Console.ReadLine(); var inputSwitch = false; string tempdietType = "unknown"; // While loop below checks to see if input was correct before going further while (inputSwitch == false) { Console.WriteLine("Please give the Dinosaur's diet type?\r\nCarnivorous/Herbivorous or c/h"); tempdietType = Console.ReadLine().ToUpper(); if (tempdietType != "C" && tempdietType != "H" && tempdietType != "CARNIVOROUS" && tempdietType != "HERBIVOROUS") { Console.WriteLine("User Input was not recognized. Please Try Again."); inputSwitch = false; } else if (tempdietType == "C" || tempdietType == "CARNIVOROUS") { tempdietType = "Carnivorous"; inputSwitch = true; } else if (tempdietType == "H" || tempdietType == "HERBIVOROUS") { tempdietType = "Herbivorous"; inputSwitch = true; } } Console.WriteLine("Please give the Dinosaur's weight in pounds? "); var tempweight = double.Parse(Console.ReadLine()); Console.WriteLine("Please give the EnclosureNumber the Dinosaur will be housed?"); var tempEnclosureNumber = int.Parse(Console.ReadLine()); DateTime tempDateTime = DateTime.Now; // Data has been gathered, time to create and add new Dinosaur Console.WriteLine($"{tempName} ID: {tempiD} has been successfully created!"); zooDinosaurs.Add(new Dinosaur() { name = tempName, dietType = tempdietType, whenAcquired = DateTime.Now, weight = tempweight, enclosureNumber = tempEnclosureNumber, iD = tempiD, }); break; // ----Remove Option---- // ||||||||||||||||||||| case "REMOVE": Console.WriteLine("Which Dinosaur do you want removed"); var nameGiven = Console.ReadLine(); var nameThatWasSearched = new List <Dinosaur>(); nameThatWasSearched.AddRange(zooDinosaurs.Where(Dinosaur => Dinosaur.name == nameGiven)); // Adventure Mode Implemented; if more than one name is returned, we prompt for specification before we remove correct Dinosaur using their ID property if (nameThatWasSearched.Count() == 0) { Console.WriteLine($"The Listed Dinosaur {nameGiven} was not found."); } else if (nameThatWasSearched.Count() == 1) { zooDinosaurs.RemoveAt(zooDinosaurs.FindIndex(Dinosaur => Dinosaur.name.Contains(nameGiven))); } else if (nameThatWasSearched.Count() > 1) { // Gives Option to specify which Dino if more than one Dino Found Console.WriteLine($"There was more than one Dinosaurs named {nameGiven}. Which one are you looking for?"); int counter = 1; var listOfChoices = new List <int>(); foreach (Dinosaur dinosaur in nameThatWasSearched) { Console.WriteLine("{" + $"{counter}" + "}" + $"-----------ID: {dinosaur.iD}-----------Name: {dinosaur.name}---------"); dinosaur.PrintDescription(); Console.WriteLine(); listOfChoices.Add(counter); counter++; } Console.Write("Choose Options:"); foreach (int options in listOfChoices) { Console.Write($" " + "{" + $"{options}" + "}"); } var optionChosen = int.Parse(Console.ReadLine()); // Space for "if input was wrong input, loop back" zooDinosaurs.RemoveAt(zooDinosaurs.FindIndex(Dinosaur => Dinosaur.iD == nameThatWasSearched[optionChosen - 1].iD)); } break; // ----Transfer Option (similar to Remove Option---- // ||||||||||||||||||||||||||||||||||||||||||||||||| case "TRANSFER": Console.WriteLine("Which Dinosaur do you want to Transfer?"); var nameGiven2 = Console.ReadLine(); var nameThatWasSearched2 = new List <Dinosaur>(); nameThatWasSearched2.AddRange(zooDinosaurs.Where(Dinosaur => Dinosaur.name == nameGiven2)); int iDOfNameGiven = 0; if (nameThatWasSearched2.Count() == 0) { Console.WriteLine($"The Listed Dinosaur {nameGiven2} was not found."); } else if (nameThatWasSearched2.Count() == 1) { iDOfNameGiven = zooDinosaurs.First(Dinosaur => Dinosaur.name == nameGiven2).iD; } else if (nameThatWasSearched2.Count() > 1) { Console.WriteLine($"There was more than one Dinosaurs named {nameGiven2}. Which one are you looking for?"); int counter = 1; var listOfChoices = new List <int>(); foreach (Dinosaur dinosaur in nameThatWasSearched2) { Console.WriteLine("{" + $"{counter}" + "}" + $"-----------ID: {dinosaur.iD}-----------Name: {dinosaur.name}---------"); dinosaur.PrintDescription(); Console.WriteLine(); listOfChoices.Add(counter); counter++; } Console.Write("Choose Options:"); foreach (int options in listOfChoices) { Console.Write($" " + "{" + $"{options}" + "}"); } var optionChosen2 = int.Parse(Console.ReadLine()); iDOfNameGiven = zooDinosaurs.First(Dinosaur => Dinosaur.iD == nameThatWasSearched2[optionChosen2 - 1].iD).iD; } if (nameThatWasSearched2.Count() != 0) { Console.WriteLine("Which Enclosure are you transfering the Dinosaur into?"); var enclosureTransfer = int.Parse(Console.ReadLine()); zooDinosaurs.First(Dinosaur => Dinosaur.iD == iDOfNameGiven).enclosureNumber = enclosureTransfer; } break; // ----Summary Option---- // |||||||||||||||||||||| case "SUMMARY": int herbDinos = zooDinosaurs.Where(Dinosaurs => Dinosaurs.dietType == "Herbivorous").Count(); int carnDinos = zooDinosaurs.Where(zooDinosaurs => zooDinosaurs.dietType == "Carnivorous").Count(); Console.WriteLine($"Currently, there are {herbDinos} Herbivores at the Zoo."); Console.WriteLine($"Also, There are {carnDinos} Carnivores at the Zoo."); break; // ----Quit Option---- // ||||||||||||||||||| case "QUIT": runTime = false; break; // ----Wrong Input Option---- // |||||||||||||||||||||||||| case "FALSE": Console.WriteLine("User Input was not recognized. Please Try Again."); break; } } }
static void Main(string[] args) { // create new dinos list hold the values of a dino var dinos = new List <Dino>(); // display welcome DisplayWelcome(); // create bool statement to determine if prog cont. var contProg = true; // create loop to decide next step depending on the user input while (contProg) { // create menu like prompt // "Choose from the menu. [V]eiw the two types of dinos. [A]dd new dino. // [R]emove a dino. [T]ransfer a dino. [S]ummary to display how many dinos. // [Q]uit. Console.WriteLine(); Console.WriteLine("Menu options: [V]iew, [A]dd, [R]emove, [T]ransfer, [S]ummary, [Q]uit."); // read response var answer = Console.ReadLine().ToUpper(); // covert to switch statement to clean up??? switch (answer) { // if input = Q case "Q": // bool = false // exit contProg = false; break; // if input = V case "V": // foreach dinosaur in list var WhenAcquired = dinos.OrderBy(monster => monster.WhenAcquired); foreach (var monster in WhenAcquired) { // Console.WriteLine("{name} is a {diet type}. I was received on {date.time}. It weights {weight}. // It is located at {enclosure number}") Console.WriteLine(monster.DinoDescription()); } // else if input = A case "A": // prompt name // prompt diet // prompt when acquired // prompt weighta // prompt enclosure number var dino = new Dino(); // create prompt for getting the dino Name dino.Name = PromptForString("What is the Dinosaurs name?"); // create prompt for getting the dino DietType dino.DietType = PromptForString("Is it a [C]arnivore or a [H]erbivore"); // create prompt that logs the current date and time dino.WhenAcquired = DateTime.Now; // create prompt for getting the dino Weight dino.Weight = PromptForInterger("How much does the dinosaur weight in lbs? "); // create prompt for getting the dino EnclosureNumber dino.EnclosureNumber = PromptForInterger("What pen number is the dinosaur be held?"); // define dino.DinoDescription from the input from the user // dino.DinoDescription = ($"NAME: {dino.Name}. TYPE: {dino.DietType}. ACQUIRED: {dino.WhenAcquired}. WEIGHT: {dino.Weight}lbs. LOCATED IN PEN #{dino.EnclosureNumber}"); // add the collections of values to the list dinos.Add(dino); break; // else if input = T case "T": // var dinoTransfer = prompt string for "what dino do you want to transfer?" var name = PromptForString("The name of the dinosaur you want to transfer: "); // var dinoToTransfer = monster by name in monster list with the name equal to // the name to be transferred Dino foundDino = dinos.FirstOrDefault(dino => dino.Name == name); if (foundDino == null) { Console.WriteLine("There are no dinosaurs here by that name"); } else { // else newPenNum = prompt for string "what is {dinoToTransfer}'s new pen number?" var newEnclosureNum = PromptForInterger($"What is {name}'s new Enclosure number?"); // dinoTransfer.EnclosureNum = newPenNum foundDino.EnclosureNumber = newEnclosureNum; } break; // else if input = R case "R": // var dinoRemove = prompt string for "What dino are you looking for?" var dinoToRemove = PromptForString("What is the name of the dinosaur that you want remove?"); // var dinoToRemove = dino by name in dino list with the name equal to the name to be deleted Dino foundDinoToRemove = dinos.FirstOrDefault(dino => dino.Name == dinoToRemove); // if false/null if (foundDinoToRemove == null) { // return no dino by that name Console.WriteLine("There are no dinosaurs by that name"); } else { // else dino.remove dino to be deleted dinos.Remove(foundDinoToRemove); // write dino was removed Console.WriteLine($"{dinoToRemove} has been removed"); } break; // else if input = S case "S": // carnivore is equal to the count of inputs "c" in dino.DietType var carnivore = dinos.Where(dino => dino.DietType == "c").Count(); // carnivore is equal to the count of inputs "h" in dino.DietType var herbivore = dinos.Where(dino => dino.DietType == "h").Count(); var dinoType = $"There are {carnivore} Carnivore[s] and {herbivore} Herbivore[s]"; Console.WriteLine(dinoType); break; } } }