Exemplo n.º 1
0
        /// <summary>
        /// display retrieve notes from text file and instantiate new notes lis
        /// </summary>
        private static List <FinchNote> DisplayRetrieveNotes()
        {
            //
            // instantiate a new list (prevents the possibility of adding to existing list)
            List <FinchNote> notes = new List <FinchNote>();

            //
            // local variables
            //
            FinchNote userNote = FinchNote.A5;
            string    dataPath;

            DisplayHeader("Retrieve Notes");

            //
            // get the file from the user
            //
            dataPath = GetDataPath();

            //
            // checks if the file path exist
            //
            if (File.Exists(dataPath))
            {
                //
                // pause for user to initiate retrieving data
                //
                Console.WriteLine("Press Enter to retrieve data from the text file.");
                Console.ReadLine();

                //
                // retrieve and data form  the file
                //
                List <string> lines = File.ReadLines(dataPath).ToList();
                foreach (string line in lines)
                {
                    if (Enum.TryParse <FinchNote>(line, out userNote))
                    {
                        notes.Add(userNote);
                    }
                }

                Console.WriteLine("The notes have been retrieved.");
            }
            else
            {
                //
                // message displayed if file not found
                //
                Console.WriteLine("The file you have entered does not exist.");
            }


            DisplayContinuePrompt();

            return(notes);
        }
Exemplo n.º 2
0
        /// <summary>
        /// display enter notes to the list
        /// </summary>
        private static List <FinchNote> DisplayAddNotes(List <FinchNote> notes)
        {
            //
            // local variables
            //
            FinchNote userNote      = FinchNote.A5;
            bool      keepAdding    = true;
            bool      validResponse = false;
            string    userResponse;

            //
            // the user can enter in help to display the instructions
            //
            Console.WriteLine("Enter 'HELP' to see instructions.");
            Console.WriteLine();
            Console.WriteLine();

            //
            // loop runs until user enters 'STOP'
            //
            while (keepAdding)
            {
                //
                // loop runs until the respones are valid
                //
                while (!validResponse)
                {
                    //
                    // prompt user for a note
                    //
                    Console.Write("Note: ");
                    userResponse = Console.ReadLine().ToUpper();

                    //
                    // parse note to enum and add to notes list
                    //
                    if (Enum.TryParse <FinchNote>(userResponse, out userNote))
                    {
                        notes.Add(userNote);

                        //
                        // enter loop for the note length, runs until the response is valid
                        //
                        while (!validResponse)
                        {
                            //
                            // prompts the user for the length
                            //
                            Console.Write("Length: ");
                            userResponse = Console.ReadLine();

                            //
                            // validates response
                            //
                            if (userResponse != "1/8" && userResponse != "1/4" && userResponse != "1/2" && userResponse != "1/1" && userResponse != "HELP")
                            {
                                //
                                // message displayed if length is invalid
                                //
                                Console.WriteLine();
                                Console.WriteLine("You have entered an invalid length for the note.");
                                Console.WriteLine("Please try agian: ");
                            }

                            //
                            // displays the instructions if the user enter help
                            //
                            else if (userResponse == "HELP")
                            {
                                DisplayEnterNotesInstructions();
                            }

                            else
                            {
                                //
                                // add length to notes list
                                //
                                switch (userResponse)
                                {
                                case "1/8":
                                    notes.Add(FinchNote.EIGHT);
                                    break;

                                case "1/4":
                                    notes.Add(FinchNote.QUARTER);
                                    break;

                                case "1/2":
                                    notes.Add(FinchNote.HALF);
                                    break;

                                case "1/1":
                                    notes.Add(FinchNote.WHOLE);
                                    break;

                                default:
                                    break;
                                }

                                validResponse = true;
                            }
                        }
                    }

                    //
                    // display instructions for the user
                    //
                    else if (userResponse == "HELP")
                    {
                        DisplayEnterNotesInstructions();
                    }

                    //
                    // executed if user enters 'rest'
                    //
                    else if (userResponse == "REST")
                    {
                        Console.Write("Enter type of rest: ");
                        userResponse = Console.ReadLine().ToUpper();

                        //
                        // validates response
                        //
                        if (userResponse != "WHOLE" && userResponse != "HALF" && userResponse != "QUARTER" && userResponse != "EIGHT")
                        {
                            //
                            // message displayed if rest  is invalid
                            //
                            Console.WriteLine();
                            Console.WriteLine("You have entered an invalid rest.");
                            Console.WriteLine("Values allowed are: whole, half, quarter, and eight.");
                            Console.WriteLine("Please try agian: ");
                        }

                        else
                        {
                            //
                            // add length to notes list
                            //
                            switch (userResponse)
                            {
                            case "WHOLE":
                                notes.Add(FinchNote.WHOLE);
                                break;

                            case "HALF":
                                notes.Add(FinchNote.QUARTER);
                                break;

                            case "QUARTER":
                                notes.Add(FinchNote.HALF);
                                break;

                            case "EIGHT":
                                notes.Add(FinchNote.EIGHT);
                                break;

                            default:
                                break;
                            }
                        }
                    }

                    //
                    // loop ends if user enters 'stop'
                    //
                    else if (userResponse == "STOP")
                    {
                        keepAdding    = false;
                        validResponse = true;
                    }

                    //
                    // message displays if note entered is invalid
                    //
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("You have entered an invalid note.");
                        Console.WriteLine("Please try agian: ");
                    }
                }
                validResponse = false;
            }

            //
            // return the list of notes
            //
            return(notes);
        }