From 7ed237d59966be0e686598a6ff24c9a2b3a94034 Mon Sep 17 00:00:00 2001 From: Nuno Fachada Date: Sat, 7 Oct 2023 17:17:56 +0100 Subject: [PATCH] =?UTF-8?q?Adicionar=20exerc=C3=ADcios=20resolvidos=20da?= =?UTF-8?q?=20aula=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aula02/Aula02.sln | 46 ++++++++ Aula02/CatFromLastWeek/Cat.cs | 106 ++++++++++++++++++ Aula02/CatFromLastWeek/CatFromLastWeek.csproj | 9 ++ Aula02/CatFromLastWeek/Feed.cs | 11 ++ Aula02/CatFromLastWeek/Mood.cs | 13 +++ Aula02/CatFromLastWeek/Program.cs | 55 +++++++++ Aula02/ClassVsStruct/ClassVsStruct.csproj | 9 ++ Aula02/ClassVsStruct/Player.cs | 15 +++ Aula02/ClassVsStruct/Program.cs | 28 +++++ Aula02/GameUnits/GameUnits.csproj | 9 ++ Aula02/GameUnits/MilitaryUnit.cs | 27 +++++ Aula02/GameUnits/Program.cs | 19 ++++ Aula02/GameUnits/SettlerUnit.cs | 17 +++ Aula02/GameUnits/Unit.cs | 32 ++++++ Aula02/GameUnits/Vector2.cs | 14 +++ Aula02/OverrideVsNew/Animal.cs | 12 ++ Aula02/OverrideVsNew/Cat.cs | 12 ++ Aula02/OverrideVsNew/Dog.cs | 12 ++ Aula02/OverrideVsNew/Elephant.cs | 13 +++ Aula02/OverrideVsNew/OverrideVsNew.csproj | 9 ++ Aula02/OverrideVsNew/Program.cs | 22 ++++ Aula02/Polimorfismo/Animal.cs | 12 ++ Aula02/Polimorfismo/Cat.cs | 12 ++ Aula02/Polimorfismo/Dog.cs | 12 ++ Aula02/Polimorfismo/Polimorfismo.csproj | 9 ++ Aula02/Polimorfismo/Program.cs | 18 +++ 26 files changed, 553 insertions(+) create mode 100644 Aula02/Aula02.sln create mode 100644 Aula02/CatFromLastWeek/Cat.cs create mode 100644 Aula02/CatFromLastWeek/CatFromLastWeek.csproj create mode 100644 Aula02/CatFromLastWeek/Feed.cs create mode 100644 Aula02/CatFromLastWeek/Mood.cs create mode 100644 Aula02/CatFromLastWeek/Program.cs create mode 100644 Aula02/ClassVsStruct/ClassVsStruct.csproj create mode 100644 Aula02/ClassVsStruct/Player.cs create mode 100644 Aula02/ClassVsStruct/Program.cs create mode 100644 Aula02/GameUnits/GameUnits.csproj create mode 100644 Aula02/GameUnits/MilitaryUnit.cs create mode 100644 Aula02/GameUnits/Program.cs create mode 100644 Aula02/GameUnits/SettlerUnit.cs create mode 100644 Aula02/GameUnits/Unit.cs create mode 100644 Aula02/GameUnits/Vector2.cs create mode 100644 Aula02/OverrideVsNew/Animal.cs create mode 100644 Aula02/OverrideVsNew/Cat.cs create mode 100644 Aula02/OverrideVsNew/Dog.cs create mode 100644 Aula02/OverrideVsNew/Elephant.cs create mode 100644 Aula02/OverrideVsNew/OverrideVsNew.csproj create mode 100644 Aula02/OverrideVsNew/Program.cs create mode 100644 Aula02/Polimorfismo/Animal.cs create mode 100644 Aula02/Polimorfismo/Cat.cs create mode 100644 Aula02/Polimorfismo/Dog.cs create mode 100644 Aula02/Polimorfismo/Polimorfismo.csproj create mode 100644 Aula02/Polimorfismo/Program.cs diff --git a/Aula02/Aula02.sln b/Aula02/Aula02.sln new file mode 100644 index 0000000..e59a750 --- /dev/null +++ b/Aula02/Aula02.sln @@ -0,0 +1,46 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatFromLastWeek", "CatFromLastWeek\CatFromLastWeek.csproj", "{68290AAD-FBA9-4823-9433-5187EA42F3DB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polimorfismo", "Polimorfismo\Polimorfismo.csproj", "{EA07B964-981F-4369-AD7C-B31EECA78409}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OverrideVsNew", "OverrideVsNew\OverrideVsNew.csproj", "{651CD352-8B54-42A2-91B8-3E57E60D61D8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassVsStruct", "ClassVsStruct\ClassVsStruct.csproj", "{C1C8C05F-2FB4-45F2-BD1C-B46AA15CC1F0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameUnits", "GameUnits\GameUnits.csproj", "{11933F5E-0FCC-42BC-8D40-8B45D2C2B73A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {68290AAD-FBA9-4823-9433-5187EA42F3DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68290AAD-FBA9-4823-9433-5187EA42F3DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68290AAD-FBA9-4823-9433-5187EA42F3DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68290AAD-FBA9-4823-9433-5187EA42F3DB}.Release|Any CPU.Build.0 = Release|Any CPU + {EA07B964-981F-4369-AD7C-B31EECA78409}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA07B964-981F-4369-AD7C-B31EECA78409}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA07B964-981F-4369-AD7C-B31EECA78409}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA07B964-981F-4369-AD7C-B31EECA78409}.Release|Any CPU.Build.0 = Release|Any CPU + {651CD352-8B54-42A2-91B8-3E57E60D61D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {651CD352-8B54-42A2-91B8-3E57E60D61D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {651CD352-8B54-42A2-91B8-3E57E60D61D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {651CD352-8B54-42A2-91B8-3E57E60D61D8}.Release|Any CPU.Build.0 = Release|Any CPU + {C1C8C05F-2FB4-45F2-BD1C-B46AA15CC1F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1C8C05F-2FB4-45F2-BD1C-B46AA15CC1F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1C8C05F-2FB4-45F2-BD1C-B46AA15CC1F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1C8C05F-2FB4-45F2-BD1C-B46AA15CC1F0}.Release|Any CPU.Build.0 = Release|Any CPU + {11933F5E-0FCC-42BC-8D40-8B45D2C2B73A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11933F5E-0FCC-42BC-8D40-8B45D2C2B73A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11933F5E-0FCC-42BC-8D40-8B45D2C2B73A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11933F5E-0FCC-42BC-8D40-8B45D2C2B73A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Aula02/CatFromLastWeek/Cat.cs b/Aula02/CatFromLastWeek/Cat.cs new file mode 100644 index 0000000..eb56dde --- /dev/null +++ b/Aula02/CatFromLastWeek/Cat.cs @@ -0,0 +1,106 @@ +using System; + +namespace CatFromLastWeek +{ + public class Cat + { + public static int MaxEnergy { get; set; } = 100; + public static int EnergyGainAfterSleep { get; set; } = 20; + public static int EnergyLossAfterPlay { get; set; } = 15; + public static int EnergyLossAfterMeow { get; set; } = 5; + + private int energy; + private Feed feedStatus; + private Random random; + private Feed[] possibleFeedStatus; + private Mood[] possibleMoods; + + public string Name { get; } + + public int Energy + { + get => energy; + private set + { + energy = value; + if (energy < 0) energy = 0; + else if (energy > MaxEnergy) energy = MaxEnergy; + } + } + + public Feed FeedStatus + { + get => feedStatus; + private set + { + feedStatus = value; + if (feedStatus < Feed.Starving) + feedStatus = Feed.Starving; + else if (feedStatus > Feed.AboutToExplode) + feedStatus = Feed.AboutToExplode; + } + } + + public Mood MoodStatus { get; private set; } + + private Cat() + { + random = new Random(); + possibleFeedStatus = (Feed[])Enum.GetValues(typeof(Feed)); + possibleMoods = (Mood[])Enum.GetValues(typeof(Mood)); + } + + public Cat(string name, int energy, Feed feedStatus, Mood moodStatus) + : this() + { + Name = name; + Energy = energy; + FeedStatus = feedStatus; + MoodStatus = moodStatus; + } + + public Cat(string name) : this() + { + Name = name; + energy = random.Next(MaxEnergy + 1); + FeedStatus = + possibleFeedStatus[random.Next(possibleFeedStatus.Length)]; + MoodStatus = RandomMoods(); + } + + private Mood RandomMoods() + { + Mood moods = 0; + int numMoods = random.Next(possibleMoods.Length) + 1; + for (int i = 0; i < numMoods; i++) + { + moods |= possibleMoods[random.Next(possibleMoods.Length)]; + } + return moods; + } + + public void Eat() + { + FeedStatus++; + } + + public void Sleep() + { + Energy += EnergyGainAfterSleep; + FeedStatus--; + MoodStatus = RandomMoods(); + } + + public void Play() + { + Energy -= EnergyLossAfterPlay; + MoodStatus = Mood.Happy; + } + + public void Meow() + { + Console.WriteLine($"{Name} says \"Meow\"!"); + Energy -= EnergyLossAfterMeow; + } + } +} diff --git a/Aula02/CatFromLastWeek/CatFromLastWeek.csproj b/Aula02/CatFromLastWeek/CatFromLastWeek.csproj new file mode 100644 index 0000000..00413a2 --- /dev/null +++ b/Aula02/CatFromLastWeek/CatFromLastWeek.csproj @@ -0,0 +1,9 @@ + + + + Exe + net7.0 + 8.0 + + + \ No newline at end of file diff --git a/Aula02/CatFromLastWeek/Feed.cs b/Aula02/CatFromLastWeek/Feed.cs new file mode 100644 index 0000000..bb1366c --- /dev/null +++ b/Aula02/CatFromLastWeek/Feed.cs @@ -0,0 +1,11 @@ +namespace CatFromLastWeek +{ + public enum Feed + { + Starving, + Hungry, + Satisfied, + Full, + AboutToExplode + } +} diff --git a/Aula02/CatFromLastWeek/Mood.cs b/Aula02/CatFromLastWeek/Mood.cs new file mode 100644 index 0000000..2593b9f --- /dev/null +++ b/Aula02/CatFromLastWeek/Mood.cs @@ -0,0 +1,13 @@ +using System; + +namespace CatFromLastWeek +{ + [Flags] + public enum Mood + { + Happy = 1 << 0, // Equivalente a 1 (0001) + Grumpy = 1 << 1, // Equivalente a 2 (0010) + IgnoringYou = 1 << 2, // Equivalente a 4 (0100) + HyperActive = 1 << 3, // Equivalente a 8 (1000) + } +} diff --git a/Aula02/CatFromLastWeek/Program.cs b/Aula02/CatFromLastWeek/Program.cs new file mode 100644 index 0000000..0606da1 --- /dev/null +++ b/Aula02/CatFromLastWeek/Program.cs @@ -0,0 +1,55 @@ +using System; + +namespace CatFromLastWeek +{ + public class Program + { + private static void Main(string[] args) + { + // Declarar os gatos + Cat cat1, cat2; + + // Alterar os valores comuns a todos os gatos + Cat.MaxEnergy = 300; + Cat.EnergyGainAfterSleep = 25; + Cat.EnergyLossAfterMeow = 2; + Cat.EnergyLossAfterPlay = 14; + + // Criar dois gatos usando os diferentes construtores + cat1 = new Cat("Lombriga"); + cat2 = new Cat( + "Minhoca", 99, Feed.Full, Mood.HyperActive | Mood.Grumpy); + + // Mostrar estado de cada gato antes das ações + Console.WriteLine("Estado inicial dos gatos:"); + + ShowCat(cat1); + ShowCat(cat2); + + Console.WriteLine("Ações dos gatos:"); + + // Gato 1 brinca e diz miau + Console.WriteLine($"\t{cat1.Name} plays"); + cat1.Play(); + Console.Write("\t"); + cat1.Meow(); + + // Gato 2 come e dorme + Console.WriteLine($"\t{cat2.Name} eats and sleeps"); + cat2.Eat(); + cat2.Sleep(); + + // Estado dos gatos após terem efetuado algumas ações + Console.WriteLine("Estado final dos gatos:"); + ShowCat(cat1); + ShowCat(cat2); + } + + private static void ShowCat(Cat cat) + { + Console.WriteLine( + "\tNome={0}, Energia={1}, Alimentação={2}, Disposição={3}", + cat.Name, cat.Energy, cat.FeedStatus, cat.MoodStatus); + } + } +} diff --git a/Aula02/ClassVsStruct/ClassVsStruct.csproj b/Aula02/ClassVsStruct/ClassVsStruct.csproj new file mode 100644 index 0000000..00413a2 --- /dev/null +++ b/Aula02/ClassVsStruct/ClassVsStruct.csproj @@ -0,0 +1,9 @@ + + + + Exe + net7.0 + 8.0 + + + \ No newline at end of file diff --git a/Aula02/ClassVsStruct/Player.cs b/Aula02/ClassVsStruct/Player.cs new file mode 100644 index 0000000..cd93785 --- /dev/null +++ b/Aula02/ClassVsStruct/Player.cs @@ -0,0 +1,15 @@ +namespace ClassVsStruct +{ + public struct Player + { + public float Health { get; set; } + public float Armor { get; set; } + + public Player(float health) + { + Health = health; + Armor = 101f; + + } + } +} \ No newline at end of file diff --git a/Aula02/ClassVsStruct/Program.cs b/Aula02/ClassVsStruct/Program.cs new file mode 100644 index 0000000..d2d1a43 --- /dev/null +++ b/Aula02/ClassVsStruct/Program.cs @@ -0,0 +1,28 @@ +using System; + +namespace ClassVsStruct +{ + public class Program + { + private static void Main(string[] args) + { + Player p1; + p1 = new Player() { Health = 21.2f, Armor = 53.9f }; + + Console.WriteLine("Valores iniciais:"); + Console.WriteLine("\tP1: Health={0}, Armor={1}", + p1.Health, p1.Armor); + + DupHealth(p1); + + Console.WriteLine("Valores finais:"); + Console.WriteLine("\tP1: Health={0}, Armor={1}", + p1.Health, p1.Armor); + } + + private static void DupHealth(Player p) + { + p.Health *= 2; + } + } +} diff --git a/Aula02/GameUnits/GameUnits.csproj b/Aula02/GameUnits/GameUnits.csproj new file mode 100644 index 0000000..00413a2 --- /dev/null +++ b/Aula02/GameUnits/GameUnits.csproj @@ -0,0 +1,9 @@ + + + + Exe + net7.0 + 8.0 + + + \ No newline at end of file diff --git a/Aula02/GameUnits/MilitaryUnit.cs b/Aula02/GameUnits/MilitaryUnit.cs new file mode 100644 index 0000000..8cecd21 --- /dev/null +++ b/Aula02/GameUnits/MilitaryUnit.cs @@ -0,0 +1,27 @@ +namespace GameUnits +{ + public class MilitaryUnit : Unit + { + public int AttackPower { get; } + public int XP { get; set; } + public override int Health => base.Health + XP; + public override float Value => AttackPower + XP; + + public MilitaryUnit( + int movement, int health, + int attackPower) + : base(movement, health) + { + AttackPower = attackPower; + XP = 0; + } + + public void Attack(Unit u) + { + // Attack some other unit + } + + public override string ToString() => + base.ToString() + $", AP={AttackPower}, XP={XP}"; + } +} \ No newline at end of file diff --git a/Aula02/GameUnits/Program.cs b/Aula02/GameUnits/Program.cs new file mode 100644 index 0000000..0c1dc9e --- /dev/null +++ b/Aula02/GameUnits/Program.cs @@ -0,0 +1,19 @@ +using System; + +namespace GameUnits +{ + public class Program + { + private static void Main(string[] args) + { + Unit mu = new MilitaryUnit(2, 100, 50); + Unit su = new SettlerUnit(5, 25); + + mu.Move(new Vector2(2, -7)); + su.Move(new Vector2(-1, 4)); + + Console.WriteLine(mu); + Console.WriteLine(su); + } + } +} diff --git a/Aula02/GameUnits/SettlerUnit.cs b/Aula02/GameUnits/SettlerUnit.cs new file mode 100644 index 0000000..c96d02f --- /dev/null +++ b/Aula02/GameUnits/SettlerUnit.cs @@ -0,0 +1,17 @@ +namespace GameUnits +{ + public class SettlerUnit : Unit + { + public override float Value => 5; + + public SettlerUnit( + int movement, int health) + : base(movement, health) + { } + + public void Settle() + { + // Criar aldeia/cidade + } + } +} \ No newline at end of file diff --git a/Aula02/GameUnits/Unit.cs b/Aula02/GameUnits/Unit.cs new file mode 100644 index 0000000..727f6bc --- /dev/null +++ b/Aula02/GameUnits/Unit.cs @@ -0,0 +1,32 @@ +using System; + +namespace GameUnits +{ + public abstract class Unit + { + private int movement; + public virtual int Health { get; set; } + public abstract float Value { get; } + + protected Unit(int movement, int health) + { + this.movement = movement; + Health = health; + } + + public void Move(Vector2 v) + { + // Assumindo vizinhança Von Neumann + int d = Math.Abs(v.X) + Math.Abs(v.Y); + + // int d = (v.X >= 0 ? v.X : -v.X) + // + (v.Y >= 0 ? v.Y : -v.Y); + + Console.WriteLine( + $"{this.GetType().Name} has moved {d} positions"); + } + + public override string ToString() => + $"HP={Health}, Val={Value}"; + } +} \ No newline at end of file diff --git a/Aula02/GameUnits/Vector2.cs b/Aula02/GameUnits/Vector2.cs new file mode 100644 index 0000000..b392d2b --- /dev/null +++ b/Aula02/GameUnits/Vector2.cs @@ -0,0 +1,14 @@ +namespace GameUnits +{ + public struct Vector2 + { + public int X { get; } + public int Y { get; } + + public Vector2(int x, int y) + { + X = x; + Y = y; + } + } +} \ No newline at end of file diff --git a/Aula02/OverrideVsNew/Animal.cs b/Aula02/OverrideVsNew/Animal.cs new file mode 100644 index 0000000..6b71d9f --- /dev/null +++ b/Aula02/OverrideVsNew/Animal.cs @@ -0,0 +1,12 @@ +using System; + +namespace OverrideVsNew +{ + public class Animal + { + public virtual string Sound() + { + return "Sound will be "; + } + } +} diff --git a/Aula02/OverrideVsNew/Cat.cs b/Aula02/OverrideVsNew/Cat.cs new file mode 100644 index 0000000..2989e85 --- /dev/null +++ b/Aula02/OverrideVsNew/Cat.cs @@ -0,0 +1,12 @@ +using System; + +namespace OverrideVsNew +{ + public class Cat : Animal + { + public override string Sound() + { + return base.Sound() + "Miau"; + } + } +} diff --git a/Aula02/OverrideVsNew/Dog.cs b/Aula02/OverrideVsNew/Dog.cs new file mode 100644 index 0000000..8ea28d8 --- /dev/null +++ b/Aula02/OverrideVsNew/Dog.cs @@ -0,0 +1,12 @@ +using System; + +namespace OverrideVsNew +{ + public class Dog : Animal + { + public override string Sound() + { + return base.Sound() + "Woof!"; + } + } +} diff --git a/Aula02/OverrideVsNew/Elephant.cs b/Aula02/OverrideVsNew/Elephant.cs new file mode 100644 index 0000000..e5cc2cf --- /dev/null +++ b/Aula02/OverrideVsNew/Elephant.cs @@ -0,0 +1,13 @@ +using System; + +namespace OverrideVsNew +{ + public class Elephant : Animal + { + public new string Sound() + { + // Som de um elefante a andar + return "Stomp, Stomp, Stomp"; + } + } +} diff --git a/Aula02/OverrideVsNew/OverrideVsNew.csproj b/Aula02/OverrideVsNew/OverrideVsNew.csproj new file mode 100644 index 0000000..00413a2 --- /dev/null +++ b/Aula02/OverrideVsNew/OverrideVsNew.csproj @@ -0,0 +1,9 @@ + + + + Exe + net7.0 + 8.0 + + + \ No newline at end of file diff --git a/Aula02/OverrideVsNew/Program.cs b/Aula02/OverrideVsNew/Program.cs new file mode 100644 index 0000000..42516f3 --- /dev/null +++ b/Aula02/OverrideVsNew/Program.cs @@ -0,0 +1,22 @@ +using System; + +namespace OverrideVsNew +{ + public class Program + { + private static void Main(string[] args) + { + Animal a0 = new Animal(); + Animal a1 = new Dog(); + Animal a2 = new Cat(); + Animal a3 = new Elephant(); + Elephant e = new Elephant(); + + Console.WriteLine($"a0 (Animal) : {a0.Sound()}"); + Console.WriteLine($"a1 (Dog) : {a1.Sound()}"); + Console.WriteLine($"a2 (Cat) : {a2.Sound()}"); + Console.WriteLine($"a3 (Elephant) : {a3.Sound()}"); + Console.WriteLine($" e (Elephant) : {e.Sound()}"); + } + } +} diff --git a/Aula02/Polimorfismo/Animal.cs b/Aula02/Polimorfismo/Animal.cs new file mode 100644 index 0000000..c5b6901 --- /dev/null +++ b/Aula02/Polimorfismo/Animal.cs @@ -0,0 +1,12 @@ +using System; + +namespace Polimorfismo +{ + public class Animal + { + public virtual string Sound() + { + return "Sound will be "; + } + } +} diff --git a/Aula02/Polimorfismo/Cat.cs b/Aula02/Polimorfismo/Cat.cs new file mode 100644 index 0000000..f82ff4e --- /dev/null +++ b/Aula02/Polimorfismo/Cat.cs @@ -0,0 +1,12 @@ +using System; + +namespace Polimorfismo +{ + public class Cat : Animal + { + public override string Sound() + { + return base.Sound() + "Miau"; + } + } +} diff --git a/Aula02/Polimorfismo/Dog.cs b/Aula02/Polimorfismo/Dog.cs new file mode 100644 index 0000000..d0ad145 --- /dev/null +++ b/Aula02/Polimorfismo/Dog.cs @@ -0,0 +1,12 @@ +using System; + +namespace Polimorfismo +{ + public class Dog : Animal + { + public override string Sound() + { + return base.Sound() + "Woof!"; + } + } +} diff --git a/Aula02/Polimorfismo/Polimorfismo.csproj b/Aula02/Polimorfismo/Polimorfismo.csproj new file mode 100644 index 0000000..00413a2 --- /dev/null +++ b/Aula02/Polimorfismo/Polimorfismo.csproj @@ -0,0 +1,9 @@ + + + + Exe + net7.0 + 8.0 + + + \ No newline at end of file diff --git a/Aula02/Polimorfismo/Program.cs b/Aula02/Polimorfismo/Program.cs new file mode 100644 index 0000000..33b7d4c --- /dev/null +++ b/Aula02/Polimorfismo/Program.cs @@ -0,0 +1,18 @@ +using System; + +namespace Polimorfismo +{ + public class Program + { + private static void Main(string[] args) + { + Animal a0 = new Animal(); + Animal a1 = new Dog(); + Animal a2 = new Cat(); + + Console.WriteLine($"a0 sound : {a0.Sound()}"); + Console.WriteLine($"a1 sound : {a1.Sound()}"); + Console.WriteLine($"a2 sound : {a2.Sound()}"); + } + } +}