public static int PickSurfaceWater()
        {
            Console.WriteLine($"Which surface water % do you prefer? \n" +
                              $"Select 1 for Small (0%-29.99%)\n" +
                              $"Select 2 for Medium(30%-59.9%) \n" +
                              $"Select 3 for Large(60.0%+)");
            ReadLine : var waterPick = Console.ReadLine();
            bool success = Int32.TryParse(waterPick, out int waterPickParse);

            if (success)
            {
            }
            else
            {
                Confirmations.NotANumber(); //Ensures input can be converted into an int.
                goto ReadLine;
            }
            if (waterPickParse < 1 || waterPickParse > 3) //Ensures number selected is within scope.
            {
                Confirmations.WithinRange();
                goto ReadLine;
            }
            else
            {
                return(waterPickParse);
            }
        }
        public static int PickPopulation()
        {
            Console.WriteLine($"Which population size do you prefer? \n" +
                              $"Select 1 for Small (Less than 10 million)\n" +
                              $"Select 2 for Medium (Between 10 million and 2.999 billion)\n" +
                              $"Select 3 for Large (3 billion +)");
            ReadLine : var popPick = Console.ReadLine();                  //reads the population selected.
            bool success = Int32.TryParse(popPick, out int popPickParse); //Parses the biome to an int to be used in the PickMyPlanet method.

            if (success)
            {
            }
            else
            {
                Confirmations.NotANumber();
                goto ReadLine;
            }
            if (popPickParse < 1 || popPickParse > 3) //Ensures number selected is within scope.
            {
                Confirmations.WithinRange();
                goto ReadLine;
            }
            else
            {
                return(popPickParse);
            }
        }
Beispiel #3
0
        //The methods below are designed to re-read every time they are called... this was done because when a user changes something, it should be reflected in the data the next time they try and call another method,
        public static void ListofPlanets(string fileName)
        {
            Console.Clear();
            var fileContents = ReadDocument.ReadFileforList(fileName);

            Calculations.ListAllPlanets(fileContents);
            Confirmations.Return();
        }
Beispiel #4
0
        public static void EditAPlanet(string fileName)
        {
            Console.Clear();
            Console.WriteLine("Perhaps the archives are incomplete?\n");
            var fileContents = ReadDocument.ReadFileforList(fileName);

            EditPlanet.AlterSWPlanets(fileName, fileContents);
            Confirmations.Return();
        }
Beispiel #5
0
        public static void CreateAPlanet(string fileName)
        {
            Console.Clear();
            Console.WriteLine("It should be here... but it isn't.\n");
            var fileContents = ReadDocument.ReadFileforList(fileName);

            WriteDocument.WriteSWPlanets(fileName, fileContents);
            Confirmations.Return();
        }
Beispiel #6
0
        public static void DeleteAPlanet(string fileName)
        {
            Console.Clear();
            Console.WriteLine("I felt a great disturbance in the Force, as if millions of voices suddenly cried out in terror and were suddenly silenced.\n");
            var fileContents = ReadDocument.ReadFileforList(fileName);

            EditPlanet.DeleteSWPlanets(fileName, fileContents);
            Confirmations.Return();
        }
Beispiel #7
0
        public static void DisplayMainMenu()
        {
            Console.WriteLine("-------------------------------------------------------------------------" +
                              "\nPlease select an option below:                                          ||\n" +
                              "[1]: Display a list of all current planets.                             ||\n" +
                              "[2]: Show some superlatives about the planets.                          ||\n" +
                              "[3]: Create a new planet                                                ||\n" +
                              "[4]: Edit an existing planet                                            ||\n" +
                              "[5]: Delete an existing planet                                          ||\n" +
                              "[6]: Answer a few questions to find a Star Wars planet that suits you!  ||\n" +
                              "[7]: Exit program                                                       ||" +
                              "\n-------------------------------------------------------------------------");
            var fileName     = ReadDocument.ReadFileforPath(); //calls read file path method to get to the directory that contains the csv and saves it as a string.
            var mainMenuPick = Console.ReadLine();             //prompts user input to get a selection.
            var success      = Int32.TryParse(mainMenuPick, out int mainMenuSelectionParse);

            if (success)
            {
                if (mainMenuSelectionParse == 1) //Called methods here and below instead of using the if statements in case I ever want to expand the program to be able to call a method without relying on user input.
                {
                    ListofPlanets(fileName);     //List planets
                }
                if (mainMenuSelectionParse == 2)
                {
                    Superlatives(fileName); //List superlatives
                }
                if (mainMenuSelectionParse == 3)
                {
                    CreateAPlanet(fileName); //Create a planet
                }
                if (mainMenuSelectionParse == 4)
                {
                    EditAPlanet(fileName); //Edit a planet
                }
                if (mainMenuSelectionParse == 5)
                {
                    DeleteAPlanet(fileName); //Delete a planet
                }
                if (mainMenuSelectionParse == 6)
                {
                    PickMyPlanet(fileName); //Primary intended function, helps user find a planet they might be interested after a short quiz.
                }
                if (mainMenuSelectionParse == 7)
                {
                    Environment.Exit(0); //Exits program.
                }
                else
                {
                    Confirmations.WithinRange(); //confirms within range.
                }
            }
            else
            {
                Confirmations.NotANumber(); //Confirms user input is a number.
            }
        }
Beispiel #8
0
        public static void Superlatives(string fileName)
        {
            Console.Clear();
            var fileContents  = ReadDocument.ReadFileforList(fileName);
            var topFivePop    = Calculations.GetMostPopulous(fileContents);
            var bottomFivePop = Calculations.GetLeastPopulous(fileContents);

            Console.WriteLine($"The top five most populous planets are: \n{ string.Join("\n", topFivePop)}");
            Console.WriteLine($"The top five least populous planets are: \n{ string.Join("\n", bottomFivePop)}");
            Confirmations.Return();
        }
Beispiel #9
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();
        }
Beispiel #10
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();
        }
Beispiel #11
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();
 }
        public static int PickBiome(List <string> biome)
        {
            int counter = 0;

            if (BiomeDict.Count == 0) //checks to verify the dict is empty.
            {
                foreach (var i in biome)
                {
                    Console.WriteLine($"Key {counter} to select {biome[counter]}"); //Prompts the user to select a biome.
                    Calculations.BiomeDict.Add(counter, biome[counter]);            //Adds each to a dictionary to be used in the PickMyPlanet scoring system.
                    counter++;
                }
            }
            else
            {
                Console.WriteLine("Please select an additional biome!");
            }

            ReadLine : var biomePick = Console.ReadLine();                    //reads the Biome selected.
            bool success = Int32.TryParse(biomePick, out int biomePickParse); //Parses the biome to an int to be used in the PickMyPlanet method.

            if (success)
            {
            }
            else
            {
                Confirmations.NotANumber();
                goto ReadLine;
            }
            if (biomePickParse > BiomeDict.Count || biomePickParse < 0)
            {
                Confirmations.WithinRange();
                goto ReadLine;
            }
            else
            {
                return(biomePickParse);
            }
        }
        public static void PrintScore(List <SWPlanets> fileContents) //checks for confirmation to display full list of scores.
        {
            Console.WriteLine("\n\nType S to display a full list of planets with their corresponding matches to your criteria," +
                              "\ntype R to return to the main menu, or type anything else to exit.");
            string selectionConfirm = Console.ReadLine().Trim().ToUpper();

            if (selectionConfirm == "S")
            {
                Console.Clear();
                Calculations.ListPlanetsScore(fileContents);
                Confirmations.Return();
            }
            if (selectionConfirm == "R")
            {
                Console.Clear();
                MainMenu.DisplayMainMenu();
            }
            else
            {
                Environment.Exit(0); //exits program.
            }

            Confirmations.Return();
        }
Beispiel #14
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();
        }