Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 24, 2020 00:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/55172c4517e579102c2c4581bd4b2a90 to your computer and use it in GitHub Desktop.
Save codecademydev/55172c4517e579102c2c4581bd4b2a90 to your computer and use it in GitHub Desktop.
Codecademy export
namespace RoverControlCenter
{
interface IDirectable
{
string GetInfo();
string Explore();
string Collect();
}
}
namespace RoverControlCenter
{
class Probe
{
public string Alias
{ get; protected set; }
public int Year
{ get; protected set; }
public Probe(string alias, int year){
Alias = alias;
Year = year;
}
public virtual string GetInfo()
{
return $"Alias: {Alias}, YearLanded: {Year}";
}
public virtual string Explore()
{
return "Rover is exploring the surface!";
}
public virtual string Collect()
{
return "Rover is collecting rocks!";
}
}
}
using System;
namespace RoverControlCenter
{
class Program
{
static void Main(string[] args)
{
//creating objects
Probe lunokhod = new MoonRover("Lunokhod 1", 1970);
Probe apollo = new MoonRover("Apollo 15", 1971);
Probe sojourner = new MarsRover("Sojourner", 1997);
Probe 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);
Probe[] 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(Probe[] iprobes){
foreach(Probe iprobe in iprobes){
Console.WriteLine(iprobe.GetInfo());
Console.WriteLine(iprobe.Explore());
Console.WriteLine(iprobe.Collect()+"\n");
}
}
}
}
namespace RoverControlCenter
{
class Rover : Probe
{
public Rover(string alias, int year) : base(alias, year)
{
}
public override string GetInfo()
{
return $"Alias: {Alias}, YearLanded: {Year}";
}
public override string Explore()
{
return "Rover is exploring the surface!";
}
public override string Collect()
{
return "Rover is collecting rocks!";
}
}
}
namespace RoverControlCenter
{
class Satellite : Probe
{
public Satellite(string alias, int year) : base(alias, year)
{
}
public override string GetInfo()
{
return $"Alias: {Alias}, YearLaunched: {Year}";
}
public override string Explore()
{
return "Satellite is exploring the far reaches of space!";
}
public override 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