C
C#5w ago
yummy_bee

✅ RPN calculator

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) { try { using (StreamWriter writer = new StreamWriter(FilePath)) { writer.WriteLine(“Result: “ + result); } } catch (Exception ex) { Console.WriteLine(“Error writing to file: “ + ex.Message); } } } }
7 Replies
yummy_bee
yummy_bee5w ago
using System; using System.IO; namespace Calculator.View { public class View { public string ErrorMessage { get; set; } public double ResultString { get; set; } public string InputString { get; set; } public string GetRPNString() { Console.WriteLine(); return Console.ReadLine(); } public void DisplayResult(double result) { Console.WriteLine("Result: " + result); } public void DisplayError(string errorMessage) { Console.WriteLine("Error: " + errorMessage); } public string ReadInputFromFile(string filePath) { using (StreamReader reader = new StreamReader(filePath)) { return reader.ReadLine(); } } public void WriteOutputToFile(string filePath, double result) { try { using (StreamWriter writer = new StreamWriter(filePath, false)) // append = false { writer.WriteLine("Result: " + result); } Console.WriteLine($"Wrote result to file: {filePath}"); } catch (Exception ex) { Console.WriteLine($"Error writing to file: {ex.Message}"); } } } } I changed the code so that I only have one class view instead but I am still not sure if this is correct
canton7
canton75w ago
Didn't you post the same thing yesterday?
yummy_bee
yummy_bee5w ago
Yes but I have changed it now and I did not get help Does this look correct I have the namespace calculator.view, the class view, the attributes ErrorMessage, ResultString, InputString, the methods GetRPNString, DisplayResult and DisplayError. And I am using StreamWriter to write to the file @canton7 @TeBeCo
canton7
canton75w ago
Sorry, but I'm not really interested in marking your code against an assignment. That's your teacher's job. I'm happy to answer specific questions, but "mark my homework" isn't really interesting to me. Good luck!
Unknown User
Unknown User5w ago
Message Not Public
Sign In & Join Server To View
yummy_bee
yummy_bee5w ago
!close
Accord
Accord5w ago
Closed!
Want results from more Discord servers?
Add your server