예제 #1
0
        /// <summary>
        /// Handles the Click event of the openToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e"> <see cref="System.EventArgs"/>The instance containing the event data.</param>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileDialog = new OpenFileDialog();

            FileDialog.InitialDirectory = @"C:\";
            FileDialog.Title = "Open a Text File";
            FileDialog.Filter = "text files|*.txt|all files|*.*";

            if (FileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            try
            {
                NewFile = new Text(FileDialog.FileName);
                WordsList = new DistinctWordList(NewFile);
                Sentences = new SentenceList(NewFile);
                NewParagraphsList = new ParagraphList(NewFile);
                DisplayAnalysis();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #2
0
파일: Driver.cs 프로젝트: JohnCaveson/.NET
        static void Main(string[] args)
        {
            
            String response;     //holds user's responses
            Text input = new Text();   //holds text input from the keyboard or text file
            bool loop;           //should the program loop again? true if yes, false if no
            
            Welcome();
            CreateUser();

            //Get text, either from keyboard or file
            while (true)
            {
                Console.WriteLine("[1]Enter text from keyboard\n[2]Open a text file to be analyzed\n");
                response = Console.ReadLine();
                if (response == "1") //entering text from keyboard
                {
                    Console.WriteLine("Input the text to be analyzed. Press enter when you have finished typing.\n");
                    response = Console.ReadLine();
                    input.setOriginalText(response);
                    break;
                }//if
                else if (response == "2") //opening text file
                {
                    loop = false;           //valid until proven otherwise
                    OpenFileDialog dlg = new OpenFileDialog();
                    dlg.Filter = "text files|*.txt;*.text|all files|*.*";
                    dlg.InitialDirectory = Application.StartupPath;
                    dlg.Title = "Select a text file to import";
                    if (DialogResult.Cancel != dlg.ShowDialog())
                    {
                        try
                        {
                            input = new Text(dlg.FileName);
                        }//try
                        catch(Exception e)
                        {
                            Console.WriteLine(e.Message);
                            loop=true;      //invalid input, loop again
                        }//catch
                    }
                    else
                        loop = true;    //user cancelled, loop again
                    
                    if(!loop)   //if input was valid
                        break;
                }//else if
                else                   //garbage input
                {
                    Console.WriteLine("You must enter either 1 or 2\n");
                }//else 
            }//while

            loop = true;           //true when the user wants to quit
            while (loop)
            {
                //menu allowing usage of other classes
                Console.WriteLine("What would you like to do with the text entered?");
                Console.WriteLine("[1] Return a list of tokens (Text class)");
                Console.WriteLine("[2] Return an alphabetized list of tokens (Words class)");
                Console.WriteLine("[3] Return the ToString() for the first sentence (Sentence class)");
                Console.WriteLine("[4] Return the ToString() for all sentences (SentenceList class)");
                Console.WriteLine("[5] Return the ToString() for the first paragraph (Paragraph class)");
                Console.WriteLine("[6] Return the ToString() for all paragraphs (ParagraphList class)");
                Console.WriteLine("[7] Tokenize & reconstruct the input with FormatText() (Utility class)");
                Console.WriteLine("[8] Exit program");

                response = Console.ReadLine();

                switch (response)
                {
                    case "1":                   //Print token list
                        input.PrintTokens();
                        break;
                    case "2":                   //Print alphabetized token list
                        Words w = new Words(input);
                        w.Display();
                        break;
                    case "3":                   //Sentence ToString()
                        Sentence s = new Sentence(input, 0);
                        Console.WriteLine("\n" + s.ToString() + "\n");
                        break;
                    case "4":                   //SentenceList
                        SentenceList sl = new SentenceList(input);
                        sl.Display();
                        break;
                    case "5":                   //Paragraph ToString()
                        Paragraph p = new Paragraph(input, 0);
                        Console.WriteLine("\n" + p.ToString() + "\n");
                        break;
                    case "6":                   //ParagraphList
                        ParagraphList pl = new ParagraphList(input);
                        pl.Display();
                        break;
                    case "7":                   //Reformatted input
                        Console.WriteLine(Utility.FormatText(input.GetTokens(), 0, (input.GetTokens().Count - 1), 5, 65));
                        break;
                    case "8":                   //Quit
                        loop = false;
                        break;
                    default:
                        Console.WriteLine("Invalid input, please try again");
                        break;
                }//switch
            }//while

            GoodbyeMessage();
            
        }//Main(string[])
예제 #3
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[])
예제 #4
0
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.Title           = "CSCI2210 - Project 1 by Chance Reichenberg, Duncan Perkins and Chris Harris";
            Console.Clear();

            Utility.WelcomeMessage("Computer Science 2210 Project 1", " Chance Reichenberg", " Duncan Perkins", " Chris Harris");
            //Variables to temporarily hold user information to be passed
            string name, email, phone;

            //Variable used to end user input
            bool isValid = true;
            User person  = null;

            try
            {
                Console.WriteLine("What is the name of the user?");
                name = Console.ReadLine();
                Console.WriteLine("\nWhat is {0}'s phone number?", name);
                phone = Console.ReadLine();
                Console.WriteLine("\nWhat is {0}'s email address?", name);
                email = Console.ReadLine();

                //User object created using values user entered.
                person = new User(name, phone, email);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                isValid = false;
                Console.WriteLine("\nThe Data you entered was not valid. Try Again.");
                Console.WriteLine("\n\n");
            }
            while (!isValid)
            {
                isValid = true;
                try
                {
                    //Retrieve user information
                    Console.WriteLine("What is the name of the user?");
                    name = Console.ReadLine();
                    Console.WriteLine("\nWhat is {0}'s phone number?", name);
                    phone = Console.ReadLine();
                    Console.WriteLine("\nWhat is {0}'s email address?", name);
                    email = Console.ReadLine();

                    //User object created using values user entered.
                    person = new User(name, phone, email);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    isValid = false;
                    Console.WriteLine("\nThe Data you entered was not valid. Try Again.");
                    Console.WriteLine("\n\n");
                }
            }//End While

            Text textData;
            Menu menu = new Menu("Project 1 Options");

            menu = menu + "Words from the File" + "Sentences from the File" + "Paragraphs from the File" + "Quit";

            string  line, inputText;
            int     textChoice;
            Choices choice = (Choices)menu.GetChoice();

            while (choice != Choices.QUIT)
            {
                switch (choice)
                {
                //Case that displays Distinct Word and Words classes
                case Choices.WORDS:

                    Utility.Skip(2);

                    //Output to ask for user input
                    Console.WriteLine("\nEnter a '0' if you wish to open a file.\n\nEnter '1' if you wish to enter a text string.");
                    line = Console.ReadLine();

                    //Takes user input and determines if it is valid or not
                    while (!Int32.TryParse(line, out textChoice) || Int32.Parse(line) < 0 || Int32.Parse(line) > 1)
                    {
                        Console.WriteLine("You did not enter a '0' or '1'. Try Again.");
                        line = Console.ReadLine();
                    }    //End While

                    //Decision statement to ask for a string input or to open a file
                    if (textChoice == 0)
                    {
                        textData = new Text();
                    }
                    else
                    {
                        Console.WriteLine("Please enter the string you wish to evaluate below.");
                        inputText = Console.ReadLine();
                        textData  = new Text(inputText, 1);
                    }    //End if

                    Utility.Skip(2);


                    //Create the text object
                    Words textWords = new Words(textData);

                    //Outputs the words class
                    textWords.Display();

                    Console.ReadKey();
                    break;

                case Choices.SENTENCES:
                    Utility.Skip(2);

                    //Output to ask for user input
                    Console.WriteLine(" Enter a '0' if you wish to open a file.\n Enter '1' if you wish to enter a text string.");
                    line = Console.ReadLine();

                    //Takes user input and determines if it is valid or not
                    while (!Int32.TryParse(line, out textChoice) || Int32.Parse(line) < 0 || Int32.Parse(line) > 1)
                    {
                        Console.WriteLine("You did not enter a '0' or '1'. Try Again.");
                        line = Console.ReadLine();
                    }    //End While

                    //Decision statement to ask for a string input or to open a file
                    if (textChoice == 0)
                    {
                        textData = new Text();
                    }
                    else
                    {
                        Console.WriteLine("Please enter the string you wish to evaluate below.");
                        inputText = Console.ReadLine();
                        textData  = new Text(inputText, 0);
                    }    //End if

                    Utility.Skip(2);

                    //Creates the SentenceList passing in the text object
                    SentenceList s = new SentenceList(textData);

                    //Outputs the SentenceList and it's stats
                    s.Display();

                    Console.ReadKey();
                    break;


                //Case that displays the paragraph and paragraphlist classes
                case Choices.PARAGRAPHS:
                    Utility.Skip(2);

                    //Output to ask for user input
                    Console.WriteLine(" Enter a '0' if you wish to open a file.\n Enter '1' if you wish to enter a text string.");
                    line = Console.ReadLine();

                    //Takes user input and determines if it is valid or not
                    while (!Int32.TryParse(line, out textChoice) || Int32.Parse(line) < 0 || Int32.Parse(line) > 1)
                    {
                        Console.WriteLine("You did not enter a '0' or '1'. Try Again.");
                        line = Console.ReadLine();
                    }    //End While

                    //Decision statement to ask for a string input or to open a file
                    if (textChoice == 0)
                    {
                        textData = new Text();
                    }
                    else
                    {
                        Console.WriteLine("Please enter the string you wish to evaluate below.");
                        inputText = Console.ReadLine();
                        textData  = new Text(inputText, 1);
                    }    //End if

                    Utility.Skip(2);

                    //Creates the paragraph object passing in the text object
                    ParagraphList paragraph = new ParagraphList(textData);

                    //Outputs the paragraph and the paragraph stats
                    Console.WriteLine(paragraph.Display());

                    Console.ReadKey();
                    break;
                }  // end of switch

                choice = (Choices)menu.GetChoice();
            }  // end of while

            try
            {
                Console.WriteLine(person.ToString());
            }
            catch (NullReferenceException e) //Catches if the user did not try to re-enter their incorrect User Data
            {
                Console.WriteLine("You did not enter appropriate user data at the start of the program when prompted to try again.");
            }
            Utility.GoodbyeMessage();
            Console.ReadKey();
        }