C#C
C#16mo 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);
}
}
}
}
Was this page helpful?