yummy_bee
✅ null reference
How do I fix possible null reference return do I add = null! after the errormessage or why does that come up as a warning?
```cs
using System;
using System.IO;
namespace Calculator.View
{
public class CalculatorView
{
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))
{
writer.WriteLine("Result: " + result);
}
Console.WriteLine($"Wrote result to file: {filePath}");
}
catch (Exception ex)
{
Console.WriteLine($"Error writing to file: {ex.Message}");
}
}
}
}
```
37 replies
✅ 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); } } } }
} } } 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); } } } }
12 replies
✅ 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); } } }
} } } 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); } } }
9 replies