Example #1
0
        /// <summary>  used to let user choose what format they want their names to be shown in.</summary>
        /// <param name="listOFNames">  takes the list of names to be displayed</param>
        public static void FormatMenu(NameList listOFNames)
        {
            UtilityNamespace.Menu FormatMenu = new UtilityNamespace.Menu("Format Menu");//menu for name format
            FormatMenu = FormatMenu + "Original Format" + "First Name First" + "Last Name First" + "Return to Name Menu";
            NameFormat formatChoice = (NameFormat)FormatMenu.GetChoice();

            switch (formatChoice)     //switch case for user choice
            {
            case NameFormat.ORIGINAL: //list names in original given format
                listOFNames.Format = NameFormat.ORIGINAL;
                listOFNames.Display();
                break;

            case NameFormat.FIRST:     //list names in First Name First format
                Tools.DisplayList(listOFNames.SortFirst());
                break;

            case NameFormat.LAST:     //list names in last name first format
                Tools.DisplayList(listOFNames.SortLast());
                break;

            case NameFormat.QUIT:     //returns to previous menu
                Console.WriteLine("Returning to Name menu");
                return;
            }
            Tools.PressAnyKey();
            return;
        }
Example #2
0
        /// <summary>  runs the main menu for loading a file or quitting</summary>
        public static void MainMenu()
        {
            UtilityNamespace.Menu main = new UtilityNamespace.Menu("Main Menu"); //creates menu for the main menu
            main = main + "Get Name List from file" + "Quit";                    //defines choices in the menu
            MainChoice choice = (MainChoice)main.GetChoice();                    //displays menu and gets the users choice

            while (choice != MainChoice.QUIT)                                    //while choice is not quit keep running
            {
                NameMenu();                                                      //calls menu for user to interact with the NameList
                choice = (MainChoice)main.GetChoice();
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            #region Window Setup
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Title           = "English to Pig Latin Translator";
            #endregion

            #region Variable setup
            String        original      = "";           //a string to hold the original untranslated string
            List <String> originalToken = null;         //a string to hold the original untranslated tokenized string
            String        strDelims     = " ,.?!/;:\n"; //delimiters to watch out for

            PigLatin pg = null;                         //creating a piglatin object named pg
            UtilityNamespace.Menu menu = new UtilityNamespace.Menu("The Menu");
            menu = menu + "Open a file" + "Tokenize" + "Display Tokens" + "Translate to Piglatin" + "Display translation" + "Quit";

            Choices choice = (Choices)menu.GetChoice();
            #endregion

            #region Menu control
            while (choice != Choices.QUIT)
            {
                switch (choice)
                {
                case Choices.OPEN:
                    Console.WriteLine("You selected Open");
                    original = getFile();    //use the getFile() method to retrieve the path to the file
                    Console.WriteLine("Finished");
                    Console.ReadKey();
                    break;

                case Choices.TOKENIZE:
                    Console.WriteLine("You selected Tokenize");
                    if (original.Equals(""))   //if original is empty (a file hasnt been selected in this case)
                    {
                        Console.WriteLine("Please select a file first");
                    }
                    else
                    {
                        originalToken = Tools.Tokenize(original, strDelims);    //storing the tokenized version of original in originalToken
                        Console.WriteLine("Finished");
                    }
                    Console.ReadLine();
                    break;

                case Choices.SHOWTOKENS:
                    Console.WriteLine("You chose to display the tokens");
                    if (originalToken == null)   //if origininalToken is empty
                    {
                        Console.WriteLine("Please tokenize your file first");
                    }
                    else
                    {
                        foreach (String item in originalToken) //for each item in originalTokens
                        {
                            Console.WriteLine(item);           //display that item
                        }
                    }

                    Console.ReadKey();
                    break;

                case Choices.TRANSLATE:
                    if (originalToken == null)    //if the user hasn't tokenized original yet
                    {
                        Console.WriteLine("Please Tokenize first");
                        Console.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine("You chose to translate");
                        pg = new PigLatin(original, strDelims);    //initilizing object pg with a new PigLatin object based on the info given
                        Console.WriteLine("Finished");
                        Console.ReadLine();
                    }
                    break;

                case Choices.DISPLAY:
                    if (pg == null)   //if the originalToken hasn't been translated (if pg is equal to null)
                    {
                        Console.WriteLine("Please Translate first");
                        Console.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine("You chose to display the translated string");
                        Console.ReadLine();
                        Console.WriteLine(pg);    //using PigLatins toString method to display the info
                        Console.ReadLine();
                    }
                    break;
                }  // end of switch

                choice = (Choices)menu.GetChoice();
            } // end of while
            #endregion
        }     // end of main
Example #4
0
        public static void Main(string[] args)
        {
            //user input for name, email address, and phone number as well as validation
            Console.WriteLine("Hello! Welcome to my first project for my Data Structures Class.");
            Console.WriteLine("My name is Greer Goodman.");
            Console.WriteLine("What is your name?\n");
            User.Name = Console.ReadLine();
            Console.WriteLine("What is your email address?\n");
            User.Email = Console.ReadLine();
            Console.WriteLine("And last but not least, what is your phone number?\n");
            User.Phone = Console.ReadLine();
            bool check = false;//checks to see if the user input valid information

            while (check == false)
            {
                if (User.TestEmail() == true && User.TestPhone() == true)
                {
                    check = true;
                }//end if
                else if (User.TestEmail() == false || User.TestPhone() == false)
                {
                    Console.WriteLine("One of the fields you entered is incorrect. Please fix it.");
                    Console.WriteLine("What is your email address?\n");
                    User.Email = Console.ReadLine();
                    Console.WriteLine("And last but not least, what is your phone number?\n");
                    User.Phone = Console.ReadLine();
                }//end if
                Console.WriteLine("Press Enter to continue.");
                Console.ReadLine();
            }//end while

            //Menu creation and implementation
            UtilityNamespace.Menu NewMenu = new UtilityNamespace.Menu("Data Structures Project 1 Menu");
            NewMenu += "1. Open a file and tokenize it";
            NewMenu += "2. Get Distinct Words";
            NewMenu += "3. Get a list of Distinct Words";
            NewMenu += "4. Get a Sentence";
            NewMenu += "5. Get a list of Sentences";
            NewMenu += "6. Get a Paragraph";
            NewMenu += "7. Get a list of Paragraphs";
            NewMenu += "8. Exit";

            int  choice = 0;       //used for switch choosing.
            Text NewText;          //varibale created here so other switches can use it
            bool OneFirst = false; // checks to see if option one has been chosen yet

            while (choice != 8)
            {
                NewMenu.Display();
                choice = NewMenu.GetChoice();
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Please select a text file to work with.");
                    OpenFileDialog OpenDlg = new OpenFileDialog();
                    OpenDlg.Filter           = "text files|*.txt;*.text|all files|*.*";
                    OpenDlg.InitialDirectory = "Project1/TextFiles";
                    OpenDlg.Title            = "Select a file with which you would like to work with.";
                    if (DialogResult.Cancel != OpenDlg.ShowDialog())
                    {
                        FileName = OpenDlg.FileName;
                    }
                    NewText  = new Text();
                    OneFirst = true;
                    break;

                case 2:
                    if (OneFirst != false)
                    {
                        DistinctWord dw = new DistinctWord();
                        Console.WriteLine(dw.ToString());
                        Console.ReadLine();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 3:
                    if (OneFirst != false)
                    {
                        Words NewWord = new Words();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 4:
                    if (OneFirst != false)
                    {
                        Sentence Sent = new Sentence();
                        Console.WriteLine(Sent.ToString());
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 5:
                    if (OneFirst != false)
                    {
                        SentenceList SentList = new SentenceList();
                        SentenceList.Display();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 6:
                    if (OneFirst != false)
                    {
                        Paragraph Para = new Paragraph();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 7:
                    if (OneFirst != false)
                    {
                        ParagraphList ParaList = new ParagraphList();
                        ParagraphList.Display();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 8:
                    Console.WriteLine("Thank{0} ({1}, {2}) for using my program. I was completely unprepared to turn this project in. Have a nice day. ", User.Name, User.Email, User.Phone);
                    Console.ReadLine();
                    Environment.Exit(0);
                    break;
                } //end switch
            }     //end while
        }         //end main(string[])
Example #5
0
        static void Main(string[] args)
        {
            #region Window Setup
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Title           = "Astronomy Study Tool";
            #endregion

            #region Variable setup
            UtilityNamespace.Menu menu = new UtilityNamespace.Menu("Welcome to the Astomony Study Tool!");
            menu = menu + "Open a file" + "Start a new quiz" + "Review last quiz (Under Construction)" + "Average Grade (Under Construction)" + "Quit";

            Choices choice = (Choices)menu.GetChoice();
            #endregion

            #region Menu control
            while (choice != Choices.QUIT)
            {
                switch (choice)
                {
                case Choices.OPEN:
                    Console.WriteLine("You selected Open");
                    original = getFile();    //use the getFile() method to retrieve the path to the file
                    Console.WriteLine("Finished");
                    Console.ReadKey();
                    break;

                case Choices.START:
                    Console.WriteLine("You chose to start a new quiz");
                    if (original.Equals(""))    //if original is empty (a file hasnt been selected in this case)
                    {
                        Console.WriteLine("Please select a file first");
                    }
                    else
                    {
                        questions = Tools.GetQuestions(original); //storing the tokenized version of original in questions
                        answers   = Tools.GetAnswers(original);   //storing the answers from original in answers

                        do
                        {
                            restart = true;    //in the case that more than one quiz is taken, restart is set back to true here to make sure we get a digit input
                            Console.Clear();
                            Console.Write("Quiz length: ");
                            Console.ForegroundColor = ConsoleColor.Red;
                            userInput = Console.ReadLine();
                            Console.ForegroundColor = ConsoleColor.White;

                            if (userInput.All(char.IsDigit))    //if all characters in userInput are digits
                            {
                                userInputNum = Convert.ToInt32(userInput);
                                restart      = false;
                                questionNums = selectQuestions(questions.Count, userInputNum);
                            }
                            else
                            {
                                Console.Clear();
                                Console.WriteLine("\aPlease only input numbers...");
                                Console.ReadLine();
                            }
                        } while (restart);     // gets quizLength val from user, and makes sure they input only digits


                        counter = 1;
                        foreach (int questionNumber in questionNums)
                        {
                            do
                            {
                                Console.Clear();

                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("\n\n\t   " + ("Question " + counter));
                                Console.Write("\t   ");
                                for (int n = 0; n < ("Question " + counter).Length; n++)
                                {
                                    Console.Write("-");
                                }
                                Console.WriteLine("\n");
                                Console.ForegroundColor = ConsoleColor.White;

                                Console.WriteLine(questions[questionNumber]);

                                Console.Write("The answer is: ");
                                Console.ForegroundColor = ConsoleColor.Red;
                                userInput = Console.ReadLine();
                                Console.ForegroundColor = ConsoleColor.White;


                                restart = true;
                                if (userInput.Length == 1)    // if userInput is only equal to one character
                                {
                                    userAnswers.Add(Convert.ToChar(userInput));
                                    restart = false;
                                }
                                else
                                {
                                    Console.Clear();
                                    Console.WriteLine("\aPlease input only one character...");
                                    Console.ReadLine();
                                }
                            } while (restart); //does this until we get an answer for the question
                            counter++;
                        }                      // presents all the questions and gathers all the users answers

                        foreach (int number in questionNums)
                        {
                            correctAnswers.Add(answers[number]);
                        }    // grabs the correct quesitons for all the questions selected

                        Console.Clear();
                        Console.WriteLine($"Total Questions: {questions.Count}\n" +
                                          $"Total Answers: {answers.Count}\n" +
                                          $"User Answers: {userAnswers.Count}\n" +
                                          $"Correct Answers: {correctAnswers.Count}");
                        Console.ReadLine();

                        do
                        {
                            exit = false;
                            #region Display Grade

                            Console.Clear();
                            grade = Tools.GetGrade(correctAnswers, userAnswers);

                            Console.Write($"You scored a ");
                            if (grade > 84)
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                            }
                            else if (grade > 70)
                            {
                                Console.ForegroundColor = ConsoleColor.Yellow;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                            }

                            Console.Write($"{Math.Round(grade, 2)}%");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine("!");

                            GetGradeTable();
                            #endregion

                            Console.ForegroundColor = ConsoleColor.White;

                            #region Question review
                            do
                            {
                                restart = true;    //in the case that more than one quiz is taken, restart is set back to true here to make sure we get a digit input
                                Console.Write("\nWould you like to review a question? Y or N:");
                                Console.ForegroundColor = ConsoleColor.Red;
                                userInput = Console.ReadLine();
                                Console.ForegroundColor = ConsoleColor.White;

                                if (userInput.Length == 1)    // if userInput is only equal to one character
                                {
                                    userInputChar = Convert.ToChar(userInput.ToLower());
                                    restart       = false;
                                }
                                else
                                {
                                    Console.Clear();
                                    Console.WriteLine("\aPlease input only one character...");
                                    Console.ReadLine();
                                }
                            } while (restart);     // gets y or n from user


                            if (userInputChar == 'y')
                            {
                                do
                                {
                                    restart = true;    //in the case that more than one quiz is taken, restart is set back to true here to make sure we get a digit input
                                    Console.Clear();
                                    GetGradeTable();
                                    Console.Write($"Please enter a number between 1 and {questionNums.Count}: ");
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    userInput = Console.ReadLine();
                                    Console.ForegroundColor = ConsoleColor.White;

                                    if (userInput.All(char.IsDigit))    //if all characters in userInput are digits
                                    {
                                        userInputNum = Convert.ToInt32(userInput);
                                    }
                                    else
                                    {
                                        Console.Clear();
                                        Console.WriteLine("\aPlease only input numbers...");
                                        Console.ReadLine();
                                    }
                                    if (userInputNum <= questionNums.Count && userInputNum > 0)
                                    {
                                        restart = false;
                                    }
                                    else
                                    {
                                        Console.Clear();
                                        Console.WriteLine($"\aPlease enter a number between 1 and {questionNums.Count}...");
                                        Console.ReadLine();
                                    }
                                } while (restart);     //  makes sure they input only digits between 1 and quesitonNums.Count

                                Console.Clear();
                                Console.WriteLine(questions[questionNums[userInputNum - 1]]);
                                Console.WriteLine($"\nYour answer was: {userAnswers[userInputNum - 1]}. The correct answer is: {correctAnswers[userInputNum - 1]}");
                                Console.ReadLine();
                            }
                            else
                            {
                                exit = true;
                            }
                            #endregion
                        } while (!exit);
                        counter        = 0;
                        userAnswers    = new List <char> {
                        };
                        correctAnswers = new List <char> {
                        };
                    }
                    Console.ReadLine();
                    break;
                }//end of switch

                choice = (Choices)menu.GetChoice();
                #endregion
            } //end of while
        }     //end of main
Example #6
0
        /// <summary>runs Name menu which controls and allows the user to change and edit the name list</summary>
        public static void NameMenu()
        {
            String FileName = Tools.OpenDialog("Find Names", "text files|*.txt"); //opens file dialog to get chosen filename

            if (FileName == null)                                                 //if file name is null return to previous menu
            {
                return;
            }
            bool ListChanged = false;                             //other redundant listchanged boolean

            String[] FileContents = Tools.FileToString(FileName); //transfers file contents to a string array
            NameList Names        = new NameList(FileContents);   //creates the name list

            for (int i = 0; i < Names.Count; i++)                 //displays contents of file
            {
                Console.WriteLine(Names[i].NameToString(NameFormat.ORIGINAL));
            }

            Tools.PressAnyKey();
            UtilityNamespace.Menu NameMenu = new UtilityNamespace.Menu("Name Menu");                               //creats name menu to  help user interact with name list
            NameMenu = NameMenu + "Add Name" + "Delete Name" + "List Names" + "Find Name" + "Return to Main Menu"; //defines choices for name menu
            NameChoice nameChoice = (NameChoice)NameMenu.GetChoice();                                              //displays name menu and gets choice

            while (nameChoice != NameChoice.QUIT)                                                                  //if name choice is quit it returns to main menu
            {
                switch (nameChoice)                                                                                //switch statement for dealing with user choice
                {
                case NameChoice.ADD:                                                                               //choice to add name to NameList
                    Console.WriteLine("Enter name to add");
                    Name newName = new Name(Console.ReadLine());                                                   //gets name to add
                    Names = Names + newName;                                                                       //adds name to namelist
                    Names.ListChange();
                    ListChanged = true;                                                                            //sets list as changed
                    break;

                case NameChoice.DELETE:                          //choice to delete a name
                    Console.WriteLine("Which name would you like to remove?");
                    Name RemoveName = Names[Console.ReadLine()]; //gets name to remove
                    Names       = Names - RemoveName;
                    ListChanged = true;                          //sets list as changed
                    break;

                case NameChoice.LIST:                                                       //choice to list the names
                    Console.WriteLine("Which format would you like the name(s) to be in?"); //prompts for user prefered name format
                    FormatMenu(Names);                                                      //calls to display format menu
                    break;

                case NameChoice.NAME:        //choice to find a name
                    Console.WriteLine("Which Name would you like to find?");
                    String   nameToFind = Console.ReadLine();
                    NameList FoundNames = Names.FindNames(nameToFind); //gets names similar to name given
                    Name     FoundName;
                    if (FoundNames.Count != 0)                         //if no names found
                    {
                        for (int i = 1; i <= FoundNames.Count; i++)    //displays each name found
                        {
                            Console.WriteLine("{0}. {1}", i, FoundNames[i - 1].NameToString(NameFormat.FIRST));
                        }
                        Console.WriteLine("These names were found, please select one. \n0 is if you did not see the name you were looking for");        //asks user to pick name from names found
                        String s = Console.ReadLine();
                        try
                        {
                            int input = Convert.ToInt32(Console.ReadLine());    //converts user input to int


                            if (input != 0 && input <= FoundNames.Count)                                      //validates name chosen
                            {
                                Console.Clear();                                                              //clears console
                                FoundName = FoundNames[input];                                                //gets name chosen from found names
                                Console.WriteLine("Found the name {0}\nWhat would you like to do with it?", FoundName.NameToString(NameFormat.ORIGINAL));
                                UtilityNamespace.Menu NameAction = new UtilityNamespace.Menu("Name Actions"); //options to remove name
                                NameAction = NameAction + "Delete The Name" + "Nothing";                      //menu for single found name
                                int choice = NameAction.GetChoice();
                                if (choice == 1)
                                {
                                    Names = Names - FoundName;    //removes name from NameList
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Invalid choice");    //throws exception if user choice is invalid
                        }
                    }
                    else
                    {
                        Console.WriteLine("Name was not found");         //if name is not found
                        Tools.PressAnyKey();
                    }
                    break;
                }
                nameChoice = (NameChoice)NameMenu.GetChoice();                                                                                 //prompts for name choice again
            }
            if (Names.ListChanged)                                                                                                             //if nameList is change ask to save
            {
                UtilityNamespace.Menu SaveMenu = new UtilityNamespace.Menu("NameList has been changed, Would you like to save it to a file?"); //save file menu
                SaveMenu = SaveMenu + "Yes" + "No";
                int SaveChoice = SaveMenu.GetChoice();
                if (SaveChoice == 1)
                {
                    Tools.SaveFileDialog("Save File", Names.ToArray(), "text files|*.txt");    // saves file
                }
            }
        }