using System.Globalization; class Program { // Main Method // Main or main static void Main(string[] args) { bool continueNewContact = true; while (continueNewContact) { try { Console.WriteLine("Enter your first name: "); string firstName = Console.ReadLine(); // declaration and assignment Console.WriteLine("Enter your last name: "); string lastName = Console.ReadLine(); // Call GETFULLNAME and assign to a local variable in Main string fullName; // declaration fullName = GetFullName(firstName, lastName); // assignment // Output the full name to the terminal Console.WriteLine($"New contact fullname: {fullName}"); Console.WriteLine("New contact fullname: " + fullName); // Append the new line of data to the log file LogDetails(firstName, lastName, fullName); // Ask the user if they want to add a new contact Console.WriteLine("Do you want to add another contact? (yes/no) "); string i_answer = Console.ReadLine().ToLower(); if (i_answer != "yes") // yes, YES, Yes { continueNewContact = false; } // if } // try catch (Exception) { Console.WriteLine("An error occurred."); } // catch } // while Console.WriteLine("Thank you for using application."); } // Main // Get Full Name Method DEFINE static string GetFullName(string firstName, string lastName) { return $"{firstName} {lastName}"; // string interpolation with template variables } // GetFullName // Log Details Method // page 553 file I/O static void LogDetails(string firstName, string lastName, string fullName) { try { // Capture the current Environment Path string folderPath = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments ), // GetFolderPath "LogFiles" ); // Combine // Handle the exception if the "LogFiles" folder does not exist in "My Documents" Directory.CreateDirectory( folderPath ); // Create the log file name as log_MMddyyyy.txt string fileName = $"log_{DateTime.Now:MMddyyyy}.txt"; // Create the full absolute file path or relative path string filePath = Path.Combine( folderPath, fileName ); // C:\Users\Administrator\Documents\LogFiles\log_07112024.txt // Capture the current date time as string to add to the row of data for the new contact string creationDate = DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss"); // Line Output // firstName, lastName, creationDate // Bob, Smith, Bob Smith, 07-11-2024 01:56:52 PM string content = $"{firstName}, {lastName}, {fullName},{creationDate} {Environment.NewLine}"; // Append the line to the txt file File.AppendAllText( filePath, content); // confirmation Console.WriteLine($"Data added to file {fileName}."); } // try catch (IOException ex) { Console.WriteLine($"Error Message: {ex.Message}"); } // catch catch (Exception ex) { Console.WriteLine($"Error Message: {ex.Message}"); } // catch } // Log Details } // class