Пример #1
0
        public static void menu()
        {
            string filePath = "";

            Console.WriteLine("What is the file location for the book? ");
            filePath = Console.ReadLine();
            Console.Clear();
            DustyBooks dusty = new DustyBooks();
            Dictionary <string, int> uniques = new Dictionary <string, int>();
            List <string>            output  = new List <string>();

            dusty.readFile(uniques, filePath);
            List <KeyValuePair <string, int> > myList = uniques.ToList();

            myList.Sort(
                delegate(KeyValuePair <string, int> firstPair,
                         KeyValuePair <string, int> nextPair)
            {
                return(firstPair.Value.CompareTo(nextPair.Value));
            }
                );
            dusty.printAverage(myList, filePath);
            Console.ReadLine();
            Console.Clear();
            char choice;

            Console.WriteLine("Which query would you like to perform?\n\n");
            Console.WriteLine("(N) # of word appearances\n");
            Console.WriteLine("(A) Words that appear specified times\n");
            Console.WriteLine("(L) Words with the specified length\n");
            Console.WriteLine("(Q) Quit");
            choice = Console.ReadLine()[0];
            choice = Char.ToUpper(choice);
            Console.Clear();

            while (choice != 'Q')
            {
                while (choice != 'B')
                {
                    if (choice == 'N')
                    {
                        Console.WriteLine("Enter the word for query\n");
                        string readWord = Console.ReadLine();
                        int    queryValue;
                        if (uniques.TryGetValue(readWord, out queryValue))
                        {
                            Console.WriteLine("'{0}' appears {1} times.", readWord, queryValue);
                        }
                        else
                        {
                            Console.WriteLine("'{0}' is not in the book", readWord);
                        }
                        Console.ReadLine();
                        Console.Clear();
                        choice = 'B';
                    }

                    if (choice == 'A')
                    {
                        Console.WriteLine("Enter the number for query\n");
                        string input = Console.ReadLine();
                        int    number;
                        Int32.TryParse(input, out number);
                        if (uniques.ContainsValue(number))
                        {
                            foreach (KeyValuePair <string, int> kvp in uniques)
                            {
                                if (kvp.Value == number)
                                {
                                    output.Add(kvp.Key);
                                }
                            }
                        }
                        output.Sort();
                        Console.Clear();
                        Console.WriteLine("The follow word(s) has {0} appearances", number);
                        Console.WriteLine();
                        foreach (string s in output)
                        {
                            Console.WriteLine(s);
                        }
                        Console.ReadLine();
                        Console.Clear();
                        output.Clear();
                        choice = 'B';
                    }

                    if (choice == 'L')
                    {
                        Console.WriteLine("Enter the number for query");
                        string input = Console.ReadLine();
                        int    number;
                        Int32.TryParse(input, out number);

                        foreach (KeyValuePair <string, int> kvp in myList)
                        {
                            if (kvp.Key.Length == number)
                            {
                                Console.WriteLine(kvp.Key + " " + kvp.Value);
                            }
                        }
                        Console.ReadLine();
                        Console.Clear();
                        choice = 'B';
                    }
                }
                Console.WriteLine("Which query would you like to perform?\n\n");
                Console.WriteLine("(N) # of word appearances\n");
                Console.WriteLine("(A) Words that appear specified times\n");
                Console.WriteLine("(L) Words with the specified length\n");
                Console.WriteLine("(Q) Quit");
                choice = Console.ReadLine()[0];
                choice = Char.ToUpper(choice);
                Console.Clear();
            }
        }
Пример #2
0
 static void Main(string[] args)
 {
     DustyBooks.menu();
 }