Hello, I’m working on this task:
Next, take the class Point from the previous task and rename it to Point2D (2D stands for two-dimensional). Also take the LitArea class and rename it to LitArea2D. Add a public method Draw() to the LitArea2D class that takes no arguments and returns void. In the Main method, read four integers from the console, each from the new line: xTopLeft , yTopLeft , xBottomRight, and yBottomRight . Create an object of type LitArea2D, passing these four integers as parameters to a constructor. These four integers represent coordinates on a 2D grid: the coordinate system starts in the top left corner; X axes are horizontal, and Y are vertical. See the following figure for an example. Implement method Draw() in the class LitArea2D to draw an area using ASCII art, according to integer coordinates that the user input. The dark area to the left and above the lit area should be indicated with a dot (“.”), and the lit area itself with a pound sign (“#”). Then, call this method from Main. For example:
>2
>3
>5
>6
…
…
…
…####
…####
…####
…####
/* In the above example, the lit area starts at point [2, 3] and ends at point [5, 6] */
Example 2:
>0
>0
>2
>4
/* In the above example, the lit area starts at point [0, 0] and ends at point [2, 4] */
Here is my code:
namespace AccessModifiers
{
class Point2D
{
public int X;
public int Y;
}
class LitArea2D
{
private Point2D _topLeft;
private Point2D _bottomRight;
public LitArea2D(int xTopLeft, int yTopLeft, int xBottomRight, int yBottomRight)
{
_topLeft = new Point2D
{
X = xTopLeft,
Y = yTopLeft
};
_bottomRight = new Point2D
{
X = xBottomRight,
Y = yBottomRight
};
}
public void Draw()
{
for (int i = 0; i <= _bottomRight.X; i++)
{
if (i < _topLeft.Y)
{
for (int j = 0; j < _bottomRight.X; j++)
{
Console.Write(".");
}
Console.WriteLine(".");
}
if (i >= _topLeft.Y && i <= _bottomRight.Y)
{
for (int j = 0; j <= _bottomRight.X; j++)
{
if (j < _topLeft.X)
{
Console.Write(".");
}
if (_topLeft.X <= j && j <= _bottomRight.X)
{
Console.Write("#");
}
}
Console.WriteLine();
}
}
}
}
class DrawLitArea
{
public static void Main()
{
int xTopLeft = int.Parse(Console.ReadLine());
int yTopLeft = int.Parse(Console.ReadLine());
int xBottomRight = int.Parse(Console.ReadLine());
int yBottomRight = int.Parse(Console.ReadLine());
var someLitArea = new LitArea2D(xTopLeft, yTopLeft, xBottomRight, yBottomRight);
someLitArea.Draw();
}
}
}
At the first glance the code works as it should, but the platform shows an error:
Tested this input and can’t understand what’s wrong.
Can anyone please help me to find my mistake?