/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (Planets game = new Planets()) { game.Run(); } }
public static void PlanetName() { string filePath = @"C:\Users\opilane\samples"; string fileName = @"planets.txt"; List <Planets> planets = new List <Planets>(); List <string> planetlist = File.ReadAllLines(Path.Combine(filePath, fileName)).ToList(); foreach (string line in planetlist) { string[] tempArray = line.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries); Planets NewPlanet = new Planets(tempArray[0], Int32.Parse(tempArray[1])); planets.Add(NewPlanet); Console.WriteLine(line); } int total = 0; foreach (Planets planet in planets) { Console.WriteLine($"Planet: {planet.Name}; Mass: {planet.Mass}"); total += planet.Mass; } Console.WriteLine($"Total mass: {total}"); }
//removes a planet from the solar system public void RemovePlanetFromSolarSystem(Planets removedPlanet) { planetsInSolarSystem.Remove(removedPlanet); }
//inserts a planet to the solarsystem public void InsertPlanetToSolarSystem(int index, Planets insertedPlanet) { planetsInSolarSystem.Insert(index, insertedPlanet); }
//adds a planet to the solar system public void AddPlanetToSolarSystem(Planets newPlanets) { planetsInSolarSystem.Add(newPlanets); }
static void Main(string[] args) { //Creates all the planets as their own object Planets mercury = new Planets("Mercury", 0.330, 4879, 5427, 3.7, 1407.6, 4222.6, 57.9, 88.0, 47.4, 167, 0, "no"); Planets venus = new Planets("Venus", 4.87, 12104, 5243, 8.9, -5832.5, 2802.0, 108.2, 224.7, 35.0, 464, 0, "no"); Planets earth = new Planets("Earth", 5.97, 12756, 5514, 9.8, 23.9, 24.0, 149.6, 365.2, 29.8, 15, 1, "no"); Planets mars = new Planets("Mars", 0.642, 6792, 3933, 3.7, 24.6, 24.7, 227.9, 687.0, 24.1, -65, 2, "no"); Planets jupiter = new Planets("Jupiter", 1898, 142984, 1326, 23.1, 9.9, 9.9, 778.6, 4331, 13.1, -110, 67, "yes"); Planets saturn = new Planets("Saturn", 568, 120536, 687, 9.0, 10.7, 10.70, 1433.5, 10747, 9.7, -140, 62, "yes"); Planets uranus = new Planets("Uranus", 86.8, 51118, 1271, 8.7, -17.2, 17.2, 2872.5, 30589, 6.8, -195, 27, "yes"); Planets neptune = new Planets("Neptune", 102, 49528, 1638, 11.0, 16.1, 16.1, 4495.1, 59.8, 5.4, -200, 14, "yes"); Planets pluto = new Planets("Pluto", 0.0146, 2370, 2095, 0.7, -153.3, 153.3, 5906.4, 90.56, 4.7, -225, 5, "no"); SolarSystem solarSystem = new SolarSystem(); //adds all the Planets to the solarSystemList. solarSystem.AddPlanetToSolarSystem(mercury); solarSystem.AddPlanetToSolarSystem(earth); solarSystem.AddPlanetToSolarSystem(mars); solarSystem.AddPlanetToSolarSystem(jupiter); solarSystem.AddPlanetToSolarSystem(saturn); solarSystem.AddPlanetToSolarSystem(uranus); solarSystem.AddPlanetToSolarSystem(neptune); solarSystem.AddPlanetToSolarSystem(pluto); //prints out all the planets in the solar system list foreach (Planets planet in solarSystem.PlanetsInSolarSystem) { Console.WriteLine("======================="); Console.WriteLine(planet); Console.WriteLine("======================="); } Console.ReadKey(); //adds venus too its place in the solar system solarSystem.InsertPlanetToSolarSystem(1, venus); //prints all the planets with venus inserted foreach (Planets planet in solarSystem.PlanetsInSolarSystem) { Console.WriteLine("======================="); Console.WriteLine(planet); Console.WriteLine("======================="); } Console.ReadKey(); //Removed pluto, since it isnt a real planet solarSystem.RemovePlanetFromSolarSystem(pluto); //prints all the planets without pluto foreach (Planets planet in solarSystem.PlanetsInSolarSystem) { Console.WriteLine("======================="); Console.WriteLine(planet); Console.WriteLine("======================="); } Console.ReadKey(); //adds back pluto solarSystem.AddPlanetToSolarSystem(pluto); //show the amount of planets in the solar system Console.WriteLine(solarSystem.PlanetsInSolarSystem.Count); Console.ReadKey(); //Write out all planets with a temperature under 0 degrees Console.WriteLine("<planets with a temperature under 0 degrees>"); solarSystem.MeanTemperaturePlanets(); foreach (Planets planets in solarSystem.MeanTemperature) { Console.WriteLine("===================="); Console.WriteLine(planets); Console.WriteLine("===================="); } Console.ReadKey(); //write out all planets with an diameter between 10000 and 50000 Console.WriteLine("<planets with an diameter between 10000 and 50000>"); solarSystem.DiameterForPlanets(); foreach (Planets planets in solarSystem.PlanetDiameter) { Console.WriteLine("===================="); Console.WriteLine(planets); Console.WriteLine("===================="); } Console.ReadKey(); //deletes everything from the list solarSystem.PlanetsInSolarSystem.Clear(); solarSystem.MeanTemperature.Clear(); solarSystem.PlanetDiameter.Clear(); }
static void Main(string[] args) { Planets mercury = new Planets("Mercury", 0.330f, 4879, 5427, 3.7f, 1407.6f, 4222.6f, 57.9f, 88, 47.4f, 167, 0, false); Planets earth = new Planets("Earth", 5.97f, 12756, 5514, 9.8f, 23.9f, 24, 149.6f, 365.2f, 29.8f, 15, 1, false); Planets mars = new Planets("Mars", 0.642f, 6792, 3933, 3.7f, 24.6f, 24.7f, 227.9f, 687, 24.1f, -65, 2, false); Planets jupiter = new Planets("Jupiter", 1898, 142984, 1326, 23.1f, 9.9f, 9.9f, 778.6f, 4331, 13.1f, -110, 67, true); Planets saturn = new Planets("Saturn", 568, 120536, 687, 9, 10.7f, 10.7f, 1433.5f, 10747, 9.7f, -140, 62, true); Planets uranus = new Planets("Uranus", 86.8f, 51118, 1271, 8.7f, -17.2f, 17.2f, 2872.5f, 30589, 6.8f, -195, 27, true); Planets neptune = new Planets("Neptune", 102, 49528, 1638, 11, 16.1f, 16.1f, 4495.1f, 59.8f, 5.4f, -200, 14, true); Planets pluto = new Planets("Pluto", 0.0146f, 2370, 2095, 0.7f, -153.3f, 153.3f, 5906.4f, 90.56f, 4.7f, -225, 5, false); Planets venus = new Planets("Venus", 0.330f, 4879, 5427, 3.7f, 1407.6f, 4222.6f, 57.9f, 88, 47.4f, 167, 0, false); List <Planets> planetList = new List <Planets>(); planetList.Add(mercury); planetList.Add(earth); planetList.Add(mars); planetList.Add(jupiter); planetList.Add(saturn); planetList.Add(uranus); planetList.Add(neptune); planetList.Add(pluto); foreach (Planets item in planetList) { Console.WriteLine(item.Name); } Console.WriteLine("\nNow with Venus\n"); planetList.Insert(1, venus); foreach (Planets item in planetList) { Console.WriteLine(item.Name); } Console.WriteLine("\nNow with out Pluto\n"); planetList.RemoveAt(8); foreach (Planets item in planetList) { Console.WriteLine(item.Name); } Console.WriteLine("\npluto is back bby\n"); planetList.Add(pluto); foreach (Planets item in planetList) { Console.WriteLine(item.Name); } Console.WriteLine("\nThe number of planets: " + planetList.Count); //now a new list with mean planets List <Planets> meanPlanetList = new List <Planets>(); meanPlanetList.Add(mars); meanPlanetList.Add(jupiter); meanPlanetList.Add(saturn); meanPlanetList.Add(uranus); meanPlanetList.Add(neptune); meanPlanetList.Add(pluto); Console.WriteLine("\nnow all the mean planets\n"); foreach (Planets item in meanPlanetList) { Console.WriteLine(item.Name); } List <Planets> mediumPlanets = new List <Planets>(); mediumPlanets.Add(venus); mediumPlanets.Add(earth); mediumPlanets.Add(neptune); Console.WriteLine("\nnow all the medium planets or rather all the planets what has a diameter over 10000 and under 50000\n"); foreach (Planets item in mediumPlanets) { Console.WriteLine(item.Name); } Console.WriteLine("\nnow to delete em all from all the lists\n"); meanPlanetList.RemoveRange(0, 5); planetList.RemoveRange(0, 9); mediumPlanets.RemoveRange(0, 2); Console.WriteLine("\ndone\n"); Console.ReadKey(); }