-
-
Save codecademydev/f1ee374302e219a27a16e29a86002520 to your computer and use it in GitHub Desktop.
Codecademy export
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
namespace RoverControlCenter | |
{ | |
interface IDirectable | |
{ | |
string GetInfo(); | |
string Explore(); | |
string Collect(); | |
} | |
} |
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
namespace RoverControlCenter | |
{ | |
class Probe | |
{ | |
/* public virtual string GetInfo() | |
{ | |
return $"Alias: {Alias}, YearLanded: {YearLanded}"; | |
} | |
public virtual string Explore() | |
{ | |
return "Rover is exploring the surface!"; | |
} | |
public virtual string Collect() | |
{ | |
return "Rover is collecting rocks!"; | |
} */ | |
} | |
} |
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; | |
namespace RoverControlCenter | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//creating objects | |
MoonRover lunokhod = new MoonRover("Lunokhod 1", 1970); | |
MoonRover apollo = new MoonRover("Apollo 15", 1971); | |
MarsRover sojourner = new MarsRover("Sojourner", 1997); | |
Satellite sputnik = new Satellite("Sputnik", 1957); | |
//calling methods on all array objects | |
Rover[] rovers = {lunokhod, apollo, sojourner}; | |
//DirectAll(rovers); | |
//Array of all probe objects using Interface type | |
IDirectable[] iprobes = {lunokhod, apollo, sojourner, sputnik}; | |
DirectAll(iprobes); | |
//following checking the tyoe of the objects/instance created in console | |
Object[] probes = {lunokhod, apollo, sojourner, sputnik}; | |
Console.WriteLine("\n"); | |
foreach(Object probe in probes){ | |
Console.WriteLine($"Tracking a {probe.GetType()}…"); | |
} | |
} | |
//method for calling and printing return strings in console using foreach loop | |
public static void DirectAll(IDirectable[] iprobes){ | |
foreach(IDirectable iprobe in iprobes){ | |
Console.WriteLine(iprobe.GetInfo()); | |
Console.WriteLine(iprobe.Explore()); | |
Console.WriteLine(iprobe.Collect()+"\n"); | |
} | |
} | |
} | |
} |
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
namespace RoverControlCenter | |
{ | |
class Rover : IDirectable | |
{ | |
public string Alias | |
{ get; private set; } | |
public int YearLanded | |
{ get; private set; } | |
public Rover(string alias, int yearLanded) | |
{ | |
Alias = alias; | |
YearLanded = yearLanded; | |
} | |
public string GetInfo() | |
{ | |
return $"Alias: {Alias}, YearLanded: {YearLanded}"; | |
} | |
public virtual string Explore() | |
{ | |
return "Rover is exploring the surface!"; | |
} | |
public virtual string Collect() | |
{ | |
return "Rover is collecting rocks!"; | |
} | |
} | |
} |
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
namespace RoverControlCenter | |
{ | |
class Satellite : IDirectable | |
{ | |
public string Alias | |
{ get; private set; } | |
public int YearLaunched | |
{ get; private set; } | |
public Satellite(string alias, int yearLaunched) | |
{ | |
Alias = alias; | |
YearLaunched = yearLaunched; | |
} | |
public string GetInfo() | |
{ | |
return $"Alias: {Alias}, YearLaunched: {YearLaunched}"; | |
} | |
public virtual string Explore() | |
{ | |
return "Satellite is exploring the far reaches of space!"; | |
} | |
public virtual string Collect() | |
{ | |
return "Satellite is collecting photographic evidence!"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment