public static void Return() //checks for user input to either return to the main menu or exit the program.
        {
            Console.WriteLine("\nType R to return to main menu, key anything else to exit program");
            string selectionConfirm = Console.ReadLine().Trim().ToUpper();

            if (selectionConfirm == "R")
            {
                Console.Clear();
                MainMenu.DisplayMainMenu();
            }
            else
            {
                Environment.Exit(0); //exits program.
            }
        }
示例#2
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();
        }
示例#3
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();
        }
        public static bool Confirm()
        //gets confirmation for different methods... if a user types y it returns true to enter an if statement.
        //It returns false to skip the if statement to either return to the main menu or exit the project.
        {
            string selectionConfirm = Console.ReadLine().Trim().ToUpper();

            if (selectionConfirm == "Y")
            {
                return(true);
            }
            if (selectionConfirm == "R")
            {
                MainMenu.DisplayMainMenu();
                Console.Clear();
                return(false);
            }
            else
            {
                return(false);
            }
        }
        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();
        }
 public static void Main(string[] args)
 {
     MainMenu.DisplayMainMenu();//User input beings.
 }
示例#7
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();
        }