C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,546 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How do I create a rectangle using the Line class in c#? The output of this code should show 4 points all connected together by lines! Please fill in where it says //TODO. Also include the Main() that way it will show the rectangle. Thank you!
namespace Rectangle {
class Rectangle {
//TODO CREATE A PRIVATE ARRAY OF 4 LINES
private Rectangle[] lines = new Rectangle[4];
//TODO CREATE PRIVATE FIELD & GET ONLY PROPERTY FOR THE AREA
private int mArea;
public int Area { get; }
public Rectangle(int x, int y, int length, int width) {
lines[0] = new Rectangle(x, y, x + width, y);
lines[1] = new Rectangle(x + width, y, x + width, y + length);
lines[2] = new Rectangle(x + width, y + length, x, y + length);
lines[3] = new Rectangle(x, y + length, x, y);
}//end
// . . .
public Rectangle(Point p0, int length, int width) {
}//end constructor
public Rectangle(Point p0, Point p1, Point p2, Point p3) {
//TODO
}//end constructor
public Rectangle(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
//TODO
}//end constructor
//MOVES RECTANGLE TO A NEW POSITION
public void Move(int newX, int NewY) {
//TODO
}
//CHANGES DIMENSIONS OF THE RECT
public void Reform(int x1, int y1, int length, int width) {
}
public void Reform(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
}
public void Draw() {
}//end method
}//end class
}//end namespace
You already posted this question and you marked it as answered !
So your problem is solved
its not all solved
The person only completed part of what i dont understand
Then don't mark it as answered
People don't read answered questions...
Sorry I didnt know im new to this website
will you help me?
The second constructor is probably this:
Maybe it needs some adjustments according to definition of Point, which is not shown.
there's more to it than just that you have to create a point class . Can you answer my other question ?
Sign in to comment
1 answer
Sort by: Most helpful
According to your description, you need four lines to form a rectangle, but in the code, you create a rectangle array. Maybe it should be an line array?
You can write a line class yourself:
One thing to note is that the figure composed of four points is not necessarily a rectangle, it may be an irregular quadrilateral. You can try to use the following code to determine whether the shape is a rectangle:
After this, the code in the constructor is the code written by Viorel-1. Now that you know the two points, you can directly create the line object.
The remaining constructor only needs to call this constructor in the code, just like what I did in the Line class.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Sign in to comment
Activity