Having issues with this codes not sure what to do? using System; using static Sy
ID: 3744532 • Letter: H
Question
Having issues with this codes not sure what to do?
using System;
using static System.Console;
public class Animals
{
[STAThread]
static void Main(string[] args)
{
Animal a = new Animal();
Tiger d = new Tiger();
Eagle c = new Eagle();
Panda s = new Panda();
makeThemTalk(a);
WriteLine();
makeThemTalk(d);
WriteLine();
makeThemTalk(c);
WriteLine();
makeThemTalk(s);
WriteLine();
}
private static void makeThemTalk(Animal a)
{
if (a is Animal)
{
WriteLine("This is America");
}
if (a is Tiger)
{
WriteLine("Tiger goes RAWR");
}
if (a is Eagle)
{
WriteLine("Eagle goes SCREEEE");
}
makeThemTalk(a is Panda);
{
WriteLine("Panda goes munch");
}
}
private static void makeThemTalk(bool v)
{
throw new NotImplementedException();
}
public class Animal { }
public class Panda : Animal { }
public class Tiger : Animal { }
public class Eagle : Animal { }
}
Explanation / Answer
Given below is the fixed code with output. Please do rate the answer if it helped. thank you.
using System;
using static System.Console;
public class Animals
{
[STAThread]
static void Main(string[] args)
{
Animal a = new Animal();
Tiger d = new Tiger();
Eagle c = new Eagle();
Panda s = new Panda();
makeThemTalk(a);
WriteLine();
makeThemTalk(d);
WriteLine();
makeThemTalk(c);
WriteLine();
makeThemTalk(s);
WriteLine();
}
private static void makeThemTalk(Animal a)
{
if (a is Tiger)
{
WriteLine("Tiger goes RAWR");
}
else if (a is Eagle)
{
WriteLine("Eagle goes SCREEEE");
}
else if(a is Panda)
{
WriteLine("Panda goes munch");
}
else if (a is Animal)
{
WriteLine("This is America");
}
}
private static void makeThemTalk(bool v)
{
throw new NotImplementedException();
}
public class Animal { }
public class Panda : Animal { }
public class Tiger : Animal { }
public class Eagle : Animal { }
}
output
-------
This is America
Tiger goes RAWR
Eagle goes SCREEEE
Panda goes munch
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.