Here is the task I have to complete. In C# using only the basic code. Nothing ad
ID: 3795354 • Letter: H
Question
Here is the task I have to complete. In C# using only the basic code. Nothing advanced yet. No loops, arrays... just accessing 2 classes and getting the basics down.
Write a program that takes a decimal value between 1 and 10 and display it as a Roman Numeral. Display an error message if the value entered is outside of the acceptable range. Write a two class solution. The second class should allow the user to input a test value.
Here is the code I have for the roman numerals, but Im getting stuck when it comes to the rest of the code. Ive deleted my code 10 times already and cant seem to find anything that works. Especially with how to make the second class for user input access the RomanNumeral class to get the values.
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter5Program1
{
class RomanNumeral
{
private int decNumber;
private string rN;
private RomanNumeral()
{
if (decNumber == 1)
{
rN = "I";
}
else if (decNumber == 2)
{
rN = "II";
}
else if (decNumber == 3)
{
rN = "III";
}
else if (decNumber == 4)
{
rN = "IV";
}
else if (decNumber == 5)
{
rN = "V";
}
else if (decNumber == 6)
{
rN = "VI";
}
else if (decNumber == 7)
{
rN = "VII";
}
else if (decNumber == 8)
{
rN = "VIII";
}
else if (decNumber == 9)
{
rN = "IX";
}
else if (decNumber == 10)
{
rN = "X";
}
WriteLine(rN);
}
}
}
Explanation / Answer
Explanation :
I have added the main method to get the input from the user.
The program will accept the decimal number from the console and return the equivalent Roman number..
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class Program
{
private static String rN;
static void Main(string[] args)
{
Console.WriteLine("Enter input decimal:"); // Prompt
int line = Convert.ToInt32(Console.ReadLine()); // Get string from user
String romanNum = Test.Program.RomanNumeral(line);
Console.WriteLine("The Roman number is: " + romanNum);
Console.ReadKey();
}
public static String RomanNumeral(int decNumber)
{
if (decNumber == 1)
{
rN = "I";
}
else if (decNumber == 2)
{
rN = "II";
}
else if (decNumber == 3)
{
rN = "III";
}
else if (decNumber == 4)
{
rN = "IV";
}
else if (decNumber == 5)
{
rN = "V";
}
else if (decNumber == 6)
{
rN = "VI";
}
else if (decNumber == 7)
{
rN = "VII";
}
else if (decNumber == 8)
{
rN = "VIII";
}
else if (decNumber == 9)
{
rN = "IX";
}
else if (decNumber == 10)
{
rN = "X";
}
else
{
rN = "There is some error with the input decimal number...";
}
// Console.WriteLine(rN);
return rN;
}
}
}