From 30b2d85e7bf304bd1c2d5a443ce7e9e1c80a937f Mon Sep 17 00:00:00 2001 From: Leana BESSON Date: Thu, 11 May 2023 12:02:01 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20plusieurs=20m=C3=A9thodeq?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Solution/Wikipet's/Console/Program.cs | 8 ++-- Solution/Wikipet's/Model/Animal.cs | 34 ++++++++++++++- Solution/Wikipet's/Model/Zootheque.cs | 62 +++++++++++++++++++++++++-- 3 files changed, 93 insertions(+), 11 deletions(-) diff --git a/Solution/Wikipet's/Console/Program.cs b/Solution/Wikipet's/Console/Program.cs index 34f78b0..5b00e57 100644 --- a/Solution/Wikipet's/Console/Program.cs +++ b/Solution/Wikipet's/Console/Program.cs @@ -84,8 +84,7 @@ class Program Console.WriteLine("LES ANIMAUX"); Console.WriteLine("\t1- Afficher les animaux"); Console.WriteLine("\t2- Ajouter un animal"); - Console.WriteLine("\t3- Modifier un animal"); - Console.WriteLine("\t4- Supprimer un animal"); + Console.WriteLine("\t3- Sélectionner un animal"); Console.WriteLine("\t9- Retour"); Console.Write("\n\tEntrer votre choix : "); @@ -99,11 +98,10 @@ class Program break; case 2: Console.Clear(); - Zootheque.AjouterAnimal(); + Zootheque.AjouterAnimal(Especetheque); break; case 3: - break; - case 4: + Zootheque.SelectionnerAnimal(); break; case 9: Console.Clear(); diff --git a/Solution/Wikipet's/Model/Animal.cs b/Solution/Wikipet's/Model/Animal.cs index ed65042..a55288a 100644 --- a/Solution/Wikipet's/Model/Animal.cs +++ b/Solution/Wikipet's/Model/Animal.cs @@ -15,9 +15,12 @@ namespace Model public string Taille { get; set; } public string Poids { get; set; } public string Alimentation { get; set; } + public Espece Espece { get; set; } + public Race? Race { get; set; } - public Animal(string nom = "Inconnu", string dateNaissance = "Inconnue", string sexe = "Inconnu", string dateAdpotion = "Inconnue", string taille = "Inconnue", string poids = "Iconnu", string alimentation = "Inconnue") + public Animal(Espece espece, string nom = "Inconnu", string dateNaissance = "Inconnue", string sexe = "Inconnu", string dateAdpotion = "Inconnue", string taille = "Inconnue", string poids = "Iconnu", string alimentation = "Inconnue", Race? race = null) { + Espece = espece; Nom = nom; DateNaissance = dateNaissance; Sexe = sexe; @@ -25,9 +28,10 @@ namespace Model Taille = taille; Poids = poids; Alimentation = alimentation; + Race = race; } - public void AfficherAnimal() + public void AfficherAnimal(Zootheque zootheque) { Console.WriteLine("\n" + Nom); Console.WriteLine("\tDate de naissance : " + DateNaissance); @@ -36,6 +40,32 @@ namespace Model Console.WriteLine("\tTaille : " + Taille); Console.WriteLine("\tPoids : " + Poids); Console.WriteLine("\tAlimentation : " + Alimentation); + Console.WriteLine("\tEspece : " + Espece.Nom); + if(Race != null) Console.WriteLine("\tRace : " + Race.Nom); + + while (true) + { + Console.WriteLine("\n\t1- Modifier"); + Console.WriteLine("\n\t1- Supprimer"); + Console.WriteLine("\t9- Retour"); + + Console.Write("\n\tEntrer votre choix : "); + int decision = Convert.ToInt32(Console.ReadLine()); + + switch (decision) + { + case 1: + zootheque.SupprimerAnimal(this); + break; + case 2: + break; + case 9: + return; + default: + Console.WriteLine("\tChoix incorrect\n"); + break; + } + } } } } diff --git a/Solution/Wikipet's/Model/Zootheque.cs b/Solution/Wikipet's/Model/Zootheque.cs index a74c4d5..2742f29 100644 --- a/Solution/Wikipet's/Model/Zootheque.cs +++ b/Solution/Wikipet's/Model/Zootheque.cs @@ -8,7 +8,7 @@ namespace Model { public class Zootheque { - HashSet ListeAnimaux = new HashSet(); + public HashSet ListeAnimaux = new HashSet(); public Zootheque() { @@ -23,14 +23,14 @@ namespace Model } } - public void AjouterAnimal () + public void AjouterAnimal(Especetheque especetheque) { Console.WriteLine("INFORMATION DE VOTRE ANIMAL"); Console.Write("Entrer le nom (appuyer sur entrer pour passer) : "); string nom = Console.ReadLine(); Console.Write("Entrer la date de naissance (appuyer sur entrer pour passer) : "); string dateNaissance = Console.ReadLine(); - Console.Write("Entrer le nouveau sexe : "); + Console.Write("Entrer le nouveau sexe (appuyer sur entrer pour passer) : "); string sexe = Console.ReadLine(); Console.Write("Entrer la date d'adoption (appuyer sur entrer pour passer) : "); string dateAdoption = Console.ReadLine(); @@ -41,7 +41,61 @@ namespace Model Console.Write("Entrer la alimentation (appuyer sur entrer pour passer) : "); string alimentation = Console.ReadLine(); - ListeAnimaux.Add(new(nom, dateNaissance, sexe, dateAdoption, taille, poids, alimentation)); + Espece? espece = null; + while (espece == null) + { + Console.Write("Entrer le nom de l'espèce : "); + string nomEspece = Console.ReadLine(); + espece = especetheque.RechercherEspece(nomEspece); + if (espece == null) + { + Console.WriteLine("Espece inconnue\n"); + } + } + + Console.Write("Entrer le nom de la race : "); + string nomRace = Console.ReadLine(); + Race race = espece.RechercherRace(nomRace); + + + ListeAnimaux.Add(new(espece, nom, dateNaissance, sexe, dateAdoption, taille, poids, alimentation, race)); + } + + public Animal? RechercherAnimal(string choix) + { + foreach (Animal animal in ListeAnimaux) + { + if (animal.Nom == choix) + { + return animal; + } + } + return null; + } + + public void SelectionnerAnimal() + { + string choix = ""; + while (choix != "-1") + { + AfficherListeAnimaux(); + + Console.Write("\n\tEntrer le nom de l'animal à sélectionner (-1 pour annuler) : "); + choix = Console.ReadLine(); + + Animal animal = RechercherAnimal(choix); + + if (animal != null) + { + animal.AfficherAnimal(); + } + else Console.WriteLine("\tChoix incorrect\n"); + } + } + + public void SupprimerAnimal(Animal animal) + { + ListeAnimaux.Remove(animal); } } }