Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace MarchNine
- {
- class Program
- {
- static void Main(string[] args)
- {
- //text file path
- string textFilePath = FilePath.GetFilePath();
- bool continueProgram;
- do
- {
- continueProgram = true;
- StandardMessages.DetermineTask();
- string taskInput = Console.ReadLine();
- if (taskInput.Equals("Add", StringComparison.OrdinalIgnoreCase))
- {
- //Get user input for the lines, then append them to the list.
- List<string> lines = DataEntry.UserInput();
- File.AppendAllLines(textFilePath, lines);
- }
- else if (taskInput.Equals("Read", StringComparison.OrdinalIgnoreCase))
- {
- ReadText.Read();
- }
- else if (taskInput.Equals("Exit", StringComparison.OrdinalIgnoreCase))
- {
- continueProgram = false;
- }
- else
- {
- StandardMessages.TaskError();
- }
- } while (continueProgram == true);
- StandardMessages.EndApplication();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MarchNine
- {
- static class FilePath
- {
- public static string GetFilePath()
- {
- //static method that returns the specified file path
- return @"C:\temp\monday string.txt";
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MarchNine
- {
- class DataEntry
- {
- //Method that takes user input, puts it in a list, and then retuns that list to the caller
- public static List<string> UserInput()
- {
- List<string> output = new List<string>();
- bool addMoreEntries = true;
- do
- {
- //Get user input from user
- Console.Write("Enter text to be stored: ");
- string readInput = Console.ReadLine();
- //Get date to add to string
- DateTime date = DateTime.Now;
- //Add user input to list
- output.Add($"{readInput}\t\t (written at {date : MM-dd-yyyy HH:mm:ss})" );
- //Ask user to continue, if yes continue loop. if no exit.
- Console.WriteLine("Add more entries? (Y/N)");
- string addMoreEntriesInput = Console.ReadLine();
- if (addMoreEntriesInput != "Y" && addMoreEntriesInput != "y")
- {
- addMoreEntries = false;
- }
- } while (addMoreEntries == true);
- return output;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace MarchNine
- {
- class ReadText
- {
- public static void Read()
- {
- //Gets file path and then writes out content of the path to Console.
- string textFilePath = FilePath.GetFilePath();
- string displayText = File.ReadAllText(textFilePath);
- Console.WriteLine("Current entries:\n");
- Console.WriteLine(displayText);
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MarchNine
- {
- class StandardMessages
- {
- public static void DetermineTask()
- {
- Console.WriteLine("What would you like to do?");
- Console.WriteLine(@"Enter ""Add"" to add lines, ""Read"" to read lines, or ""Exit"" to exit program");
- }
- public static void EndApplication()
- {
- Console.WriteLine("Program Complete");
- Console.ReadLine();
- }
- public static void TaskError()
- {
- Console.WriteLine("Entry not recognized. Please enter a correct task");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement