Week 7
Week 7
class MainClass
{
static void Main(string[] args)
{
choices();
}
static void choices()
{
Console.WriteLine("What do you want?\nA.Create\nB.List all");
string? choice = Console.ReadLine();
switch (choice?.ToLower())
{
case "a":
Console.WriteLine("A.Dog\nB.Cat\nC.Bat\nD.Go Back");
string? choice2 = Console.ReadLine();
executeChoice2(choice2);
break;
case "b":
int iterator = 1;
executeChoiceB(iterator);
break;
default:
break;
}
}
static void executeChoiceB(int iterator)
{
//Console.WriteLine(Dogs[0].Id);
Dog dogs = new Dog();
Cat cats = new Cat();
Bat bats = new Bat();
bool found = dogs.getDog(iterator);
Console.WriteLine(iterator);
switch(found)
{
case true:
executeChoiceB(iterator + 1);
break;
case false:
bool foundCat = cats.getCat(iterator);
switch (foundCat)
{
case true:
executeChoiceB(iterator + 1);
break;
case false:
bool foundBat = bats.getBat(iterator);
switch (foundBat)
{
case true:
executeChoiceB(iterator + 1);
break;
case false:
choices();
break;
}
break;
}
break;
}
}
static void executeChoice2(string? choice)
{
switch (choice?.ToLower())
{
case "a":
Console.WriteLine("Input legcount");
string? legCountString = Console.ReadLine();
int legCount = 0;
if (int.TryParse(legCountString, out legCount))
{
Console.WriteLine("Input color");
string? color = Console.ReadLine();
Dog dog = new Dog(color, legCount);
Console.WriteLine("Dog successfully created with id of: " +
dog.Id);
choices();
}
else
{
Console.WriteLine("Sorry, a non numeric value was input.");
executeChoice2(choice);
}
break;
case "b":
Console.WriteLine("Input Eye color");
string? eyeColor = Console.ReadLine();
double height = 0;
Console.WriteLine("Input height");
string? heightString = Console.ReadLine();
if (double.TryParse(heightString, out height))
{
Cat cat = new Cat(eyeColor, height);
Console.WriteLine("Cat successfully created with id of: " +
cat.Id);
choices();
}
else
{
Console.WriteLine("Sorry, a non numeric value was input.");
executeChoice2(choice);
}
break;
case "c":
Console.WriteLine("Input Hair Color");
string? hairColor = Console.ReadLine();
double wingspan = 0;
Console.WriteLine("Input wingspan");
string? wingspanString = Console.ReadLine();
if (double.TryParse(wingspanString, out wingspan))
{
Bat bat = new Bat(hairColor, wingspan);
Console.WriteLine("Bat successfully created with id of: " +
bat.Id);
choices();
}
else
{
Console.WriteLine("Sorry, a non numeric value was input.");
executeChoice2(choice);
}
break;
default:
break;
}
}
}