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[])
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(); }