Пример #1
0
        public static void DeleteSWPlanets(string fileName, List <SWPlanets> sw)
        {
            ListPlanets(sw); // calls the list sw planets to display names and numbers of planets.
            var selectionDeleteParse      = SelectSWPlanetsEdit(sw);
            var storedNameforConfirmation = sw[selectionDeleteParse].Name;

            if (Confirmations.Confirm()) //calls the confirmation method to check to see if user confirms.
            {
                ReWriteSWPlanets(fileName, sw, selectionDeleteParse);
            }
            else
            {
                Console.Clear();
                MainMenu.DisplayMainMenu();
            }
            Console.Clear();
            Console.WriteLine($"{storedNameforConfirmation} has been deleted.");
            MainMenu.DisplayMainMenu();
        }
Пример #2
0
        public static void AlterSWPlanets(string fileName, List <SWPlanets> sw)
        {
            ListPlanets(sw); // calls the list sw planets to display names and numbers of planets.
            var selectionEditParse        = SelectSWPlanetsEdit(sw);
            var storedNameforConfirmation = sw[selectionEditParse].Name;;

            if (Confirmations.Confirm()) //calls the confirmation method to check to see if user confirms.
            {
                ReWriteSWPlanets(fileName, sw, selectionEditParse);
                WriteDocument.WriteSWPlanets(fileName, sw); //Calls the WriteSWPlanet Method to add back the selected planets with the new info.
            }
            else
            {
                Console.Clear();
                MainMenu.DisplayMainMenu();
            }
            Console.Clear();
            Console.WriteLine($"{storedNameforConfirmation} has been edited.");
            MainMenu.DisplayMainMenu();
        }
Пример #3
0
 public static void PickMyPlanet(string fileName)
 {
     Console.Clear();
     Console.WriteLine("You will answer a couple of questions and select three biomes of choice. " +
                       "\nFor each answer you give it will find all of the planets that meet that critera. " +
                       "\nWhen finished it will display a list of the top five planets with \nthe most amount of matches to your critera." +
                       "\n \nPress Y to continue, R to return to the main menu or anything else to exit.");
     if (Confirmations.Confirm())
     {
         Calculations.DictClear();                                      //clears the dictionary so the test can be retaken.
         var fileContents     = ReadDocument.ReadFileforList(fileName); //reads doc
         var biomes           = Calculations.GetBiomes(fileContents);   //gets a list of biome
         var pickPop          = Calculations.PickPopulation();          //prompts population pick
         var pickBiome        = Calculations.PickBiome(biomes);         //next three questions take biome selections.
         var pickBiome2       = Calculations.PickBiome(biomes);
         var pickBiome3       = Calculations.PickBiome(biomes);
         var pickSurfaceWater = Calculations.PickSurfaceWater();                                                //prompts and reads surface water question
         Calculations.PickMyPlanet(pickPop, pickBiome, pickBiome2, pickBiome3, pickSurfaceWater, fileContents); //takes all the previous variables to get score.
         Confirmations.PrintScore(fileContents);                                                                //Prints score.
     }
     Confirmations.Return();
 }
Пример #4
0
        public static void WriteSWPlanets(string fileName, List <SWPlanets> sw)
        {
            if (File.Exists(fileName))
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))  //allows appends to files without reading the entire doc and writing on to it.
                {
                    var newSWP = new SWPlanets();
                    Console.WriteLine("First enter in a planet name");
                    newSWP.Name = Console.ReadLine();
                    Console.WriteLine("Now enter in an rotational period, enter 0 if unknown. No letters!");
                    ReadRotation : if (Int32.TryParse(Console.ReadLine(), out int Rotation) && Rotation >= 0) //parses selection, the following code then attaches the newSWP and the selected values to a SWPlanet object.
                    {
                        newSWP.Rotation_period = Rotation;
                    }
                    else
                    {
                        Console.WriteLine("Please enter a valid selection..." +
                                          "\ntry and not enter too many zeros! No negatives!");
                        goto ReadRotation;
                    }
                    Console.WriteLine("Now enter in an orbital period, enter 0 if unknown. No letters!");
                    ReadOrbit : if (Int32.TryParse(Console.ReadLine(), out int Orbit) && Orbit >= 0)
                    {
                        newSWP.Orbital_period = Orbit;
                    }
                    else
                    {
                        Console.WriteLine("Please enter a valid selection... " +
                                          "\ntry and not enter too many zeros!  No negatives!");
                        goto ReadOrbit;
                    }
                    Console.WriteLine("Now enter in a Diameter in km, enter 0 if unknown. No letters!");
                    ReadDiameter : if (Int32.TryParse(Console.ReadLine(), out int Diameter) && Diameter >= 0)
                    {
                        newSWP.Diameter = Diameter;
                    }
                    else
                    {
                        Console.WriteLine("Please enter a valid selection... " +
                                          "\ntry and not enter too many zeros!  No negatives!");
                        goto ReadDiameter;
                    }
                    Console.WriteLine("Now enter in Climate information, in order to correctly submit multiple entries," +
                                      "\nplease key as comma seperated values without spaces- I.E. - temperate,arctic");
                    newSWP.Climate = Console.ReadLine();
                    Console.WriteLine("Please enter the graviational constant. If unknown, please type 0");
                    newSWP.Gravity = Console.ReadLine();
                    Console.WriteLine("Now enter in Terrain information, in order to correctly submit multiple entries, " +
                                      "\nplease key as comma seperated values without spaces- " +
                                      "\nI.E. -mountains,seas,grasslands,deserts");
                    newSWP.Terrain = Console.ReadLine();
                    Console.WriteLine("Please enter in the percentage of the planet covered in water " +
                                      "\nrepresented as an integer, if unknown, please type 0");
                    ReadWater : if (Int32.TryParse(Console.ReadLine(), out int Water) && Water >= 0)
                    {
                        newSWP.Surface_water = Water;
                    }
                    else
                    {
                        Console.WriteLine("Please enter a valid selection... " +
                                          "\ntry and not enter too many zeros!  No negatives!");
                        goto ReadWater;
                    }
                    Console.WriteLine("Please key the population as a whole number. If unknown, please put 0.");
                    ReadPopulation : if (Int64.TryParse(Console.ReadLine(), out Int64 Population) && Population >= 0)
                    {
                        newSWP.Population = Population;
                    }
                    else
                    {
                        Console.WriteLine("Please enter a valid selection... " +
                                          "\ntry not to put too many zeros!  No negatives!");
                        goto ReadPopulation;
                    }

                    Console.WriteLine($"Confirm you would like to add {newSWP.Name} as a planet. Key Y to confirm, Key anything else to cancel and return to the main menu");
                    if (Confirmations.Confirm())                                                                                                                                                                                                  //calls the confirmation method to check to see if user confirms.
                    {
                        var newPlanet = String.Join(",", newSWP.Name, newSWP.Rotation_period, newSWP.Orbital_period, newSWP.Diameter, $"\"{newSWP.Climate}\"", newSWP.Gravity, $"\"{newSWP.Terrain}\"", newSWP.Surface_water, newSWP.Population); //Joins the objects attributes. Adds double quotations to fields that could have additional commas.
                        using (StreamWriter sww = new StreamWriter(fs))
                        {
                            sww.WriteLine($"{newPlanet}"); //appends string to the end of the csv.
                        }
                    }
                    else
                    {
                        MainMenu.DisplayMainMenu();
                    }
                    Console.Clear();
                    Console.WriteLine($"{newSWP.Name} has been created.");
                }
            }
            MainMenu.DisplayMainMenu();
        }