Define a rectangle class with length, witdh, coor (x), coor (y). Then write the following methods: (Create a border named rectangle with variables length ,width, color (x), color (y) and do the following operations.) a) It stores four global variables for length, witdh, coorx and coory. (create four integer variables.) b) Two constructors: default and user defined (overloaded). (Create a class called rectangle with variables and do the following.)) c) move() method that moves rectangle in x and y directions.(Create a method named move() that takes parameters and move the rectangle in the x and y directions. Annotation: motion operation takes the parX and parY parameters given to the method, increasing or decreasing the coorx and coory variables will be) d) write two get methods which return perimeter and area. (calculate the area and perimeter of the rectangle Write two methods that return) e) write main method to test these two constructors by using array of rectangles which has two items. (Create two separate objects of the rectangle class in main(). The first object is the default constructor and the other will be created using the overloaded constructor.)
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
(( C# object oriented programming ))
the question is in attach: I will sent the code for the question, I need another way, you can update this code:
Begin:***************
using System;
namespace Rectangle
{
class Program
{
static void Main(string[] args)
{
Rectangle[] rectArray = new Rectangle[2];
rectArray[0] = new Rectangle();
rectArray[1] = new Rectangle(10, 20, 1, 2);
for (int index = 0; index < rectArray.Length; index++)
{
Console.WriteLine("Rectangle " + (index + 1) + " details");
Console.WriteLine("Area: " + rectArray[index].GetArea());
Console.WriteLine("Perimeter: " + rectArray[index].GetPerimeter());
Console.WriteLine();
}
}
public class Rectangle
{
private int length;
private int width;
private int coorx;
private int coory;
public int Length
{
get { return length; }
set { length = value; }
}
public int Width
{
get { return width; }
set { width = value; }
}
public int Coorx
{
get { return coorx; }
set { coorx = value; }
}
public int Coory
{
get { return coory; }
set { coory = value; }
}
public Rectangle()
{
this.length = 0;
this.width = 0;
this.coorx = 0;
this.coory = 0;
}
public Rectangle(int length, int width, int coorx, int coory)
{
this.length = length;
this.width = width;
this.coorx = coorx;
this.coory = coory;
}
public void move(int parX, int parY)
{
this.coorx += parX;
this.coory += parY;
}
public double GetPerimeter()
{
return 2 * (this.length + this.width);
}
public double GetArea()
{
return this.length * this.width;
}
}
}
}
End******************
Step by step
Solved in 2 steps with 2 images