Commit 3cac9800 authored by TTK18SP Mustakangas Joni Johannes's avatar TTK18SP Mustakangas Joni Johannes 🤴🏻
Browse files

Week4 inheritanse

parent 814c9cad
using System;
using System.Collections.Generic;
using System.Text;
namespace Olioita
{
class Cow : Animal
{
private ConsoleColor cowColor = ConsoleColor.White;
public void SetCowColor(ConsoleColor inputColor)
{
cowColor = inputColor;
}
}
}
......@@ -11,12 +11,14 @@ static void Main(string[] args)
{
while (letsLoop)
{
Console.WriteLine("Create dog or bird. Write bird or dog");
Console.WriteLine("Create dog, bird or cow. Write bird, dog or cow");
string x = Console.ReadLine(); //Luetaan input ja konvertoidaan kaikki characterit lower caseksi
if (x == "bird")
CreateBird();
else if (x == "dog")
CreateDog();
else if (x == "cow")
CreateCow();
else
Console.WriteLine("Input not walid");
ListAllAnimals();
......@@ -24,7 +26,6 @@ static void Main(string[] args)
}
Console.WriteLine("Luuppi loppu");
}
static void AskUserIfWeConinueLoop()
......@@ -46,7 +47,27 @@ static void CreateDog()
tempDogName.Name = name;
animals.Add(tempDogName);
}
static void CreateCow()
{
Console.WriteLine("Give cow a name");
string name = Console.ReadLine(); // Otetaan talteen nimi
Console.WriteLine("Give cow a color");
string color = Console.ReadLine(); // Otetaan talteen rotu
try//Koitetaan ja napataan errrori
{
ConsoleColor c = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), color); //convertoidaan stringi ConsolColoriksi
Cow tempCow = new Cow(); // luodaan valiaikainen lehma
tempCow.Name = name;
tempCow.SetCowColor(c); // asetetaan vari lehmalle
animals.Add(tempCow);
}
catch (Exception)
{
Console.WriteLine("Cant create cow, input not ConsolColor");
//throw;
}
}
static void CreateBird()
{
Console.WriteLine("Give bird a name");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment