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[])
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[])