Created
July 6, 2015 21:31
-
-
Save 200even/875b85dd24eb0d9cfe18 to your computer and use it in GitHub Desktop.
Scott Week 2 Day 1 Humans Pandas Robots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Humans_Robots_and_Pandas | |
{ | |
public interface IAllBeings | |
{ | |
bool IsAsleep { get; set; } | |
string Name { get; set; } | |
string DisplayGreeting(); | |
string DisplayName(); | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Need to populate the classes | |
Human Daniel = new Human(); | |
Human Scott = new Human(); | |
Human Arnold = new Human(); | |
Panda Jack = new Panda(); | |
Panda Bob = new Panda(); | |
Robot Spark = new Robot(); | |
Robot Bolt = new Robot(); | |
Robot T100 = new Robot(); | |
T100.IsTerminator = true; | |
T100.Name = "T100"; | |
List<Human> humans = new List<Human> { Daniel, Scott, Arnold }; | |
List<Panda> pandas = new List<Panda> { Jack, Bob }; | |
List<Robot> robots = new List<Robot> { Spark, Bolt, T100 }; | |
List<IAllBeings> errrrbody = new List<IAllBeings>(); | |
errrrbody.AddRange(humans); | |
errrrbody.AddRange(pandas); | |
errrrbody.AddRange(robots); | |
foreach (var e in errrrbody) | |
{ | |
if (e is Robot) | |
{ | |
Console.WriteLine(((Robot)e).IsTerminator); | |
} | |
}//end foreach | |
var terminators = robots.Where(x => x.IsTerminator); | |
foreach(var t in terminators) | |
{ | |
Console.WriteLine("{0} is a terminator.", t); | |
} | |
Console.ReadLine(); | |
} | |
} | |
public abstract class AllBeings : IAllBeings | |
{ | |
public string Name { get; set; } | |
public string DisplayName() | |
{ | |
return String.Format("Hello my name is {0}.", this.Name); | |
} | |
public string DisplayGreeting() | |
{ | |
return String.Format("Greetings!"); | |
} | |
public bool IsAsleep { get; set; } | |
public override string ToString() | |
{ | |
return Name; | |
} | |
} | |
public class OrganicBeings : AllBeings | |
{ | |
public string Eat(string food) | |
{ | |
return "Yum, I ate " + food + "."; | |
} | |
public void GoToSleep() | |
{ | |
IsAsleep = true; | |
} | |
public void WakeUp() | |
{ | |
IsAsleep = false; | |
} | |
} | |
public class Human : OrganicBeings | |
{ | |
public override string ToString() | |
{ | |
return "My name is " + Name + "."; | |
} | |
} | |
public class Panda : OrganicBeings | |
{ | |
} | |
public class Robot : AllBeings | |
{ | |
public string ShutDown() | |
{ | |
IsAsleep = true; | |
return "Shutting down..."; | |
} | |
public string StartUp() | |
{ | |
IsAsleep = false; | |
return "Starting up..."; | |
} | |
public bool IsTerminator { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment