C
C#3mo ago
yummy_bee

✅ help with assignment

I am coding a RPN calculator and I am supposed to do the calculator.view part and I just want to make sure I am doing it right. This is the code I have written so far and I attached the instructions. //Calculator.view// using System; using System.IO; namespace Calculator.View { public class Calculator { public string GetRPNString() { Console.WriteLine(); return Console.ReadLine(); } } } namespace Calculator.View { public class UserInput { public void DisplayResult(double ResultString) { Console.WriteLine("Result:" + ResultString); } public void DisplayError(string ErrorMessage) { Console.WriteLine("Error: " + ErrorMessage); } } } namespace Calculator.View { public class FileInput { private string FilePath; public FileInput(string filePath) { FilePath = filePath; } public string ReadInputFromFile() { using (StreamReader reader = new StreamReader(FilePath)) { return reader.ReadLine(); }
} } } namespace Calculator.View { public class FileOutput { private string FilePath; public FileOutput(string filePath) { FilePath = filePath; } public void WriteOutputToFile(double result) { Console.WriteLine(FilePath, "Results: " + result); } } }
3 Replies
Buddy
Buddy3mo ago
Doing what correctly, exactly? You are not calculating anything there And not sure why FileInput and FileOutput is in View
yummy_bee
yummy_beeOP3mo ago
The view part is only for input and output so I am not supposed to calculate anything I am using file input and file output to write to a file because in the instructions it says it should be supported by two interfaces console based and file based I realize that I did not write to a file in the file output so I changed that. namespace Calculator.View { public class FileOutput { private string FilePath; public FileOutput(string filePath) { FilePath = filePath; } public void WriteOutputToFile(double result) { try { File.WriteAllText(FilePath, "Result: " + result); } catch (Exception ex) { Console.WriteLine("Error writing to file: " + ex.Message); } } } } Could someone help me check if I have done this right? !close
Accord
Accord3mo ago
Closed!
Want results from more Discord servers?
Add your server