This code defines a Rectangle class with length and width properties. It includes a constructor to set the length and width, an area method to calculate the area, and a display method to print the rectangle to the console. The Main method creates a rectangle1 object, calls its display method, and later modifies the code to create two additional rectangles, rectangle2 and rectangle3 with different dimensions, and calls display on each.
Unit-IV; Professional Sales Representative (PSR).pptx
Paste the following code in the w3 editorusing System;namespace .pdf
1. Paste the following code in the w3 editor
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Rectangle rectangle1 = new Rectangle(8,8);
rectangle1.display();
}
}
class Rectangle
{
int length;
int width;
public Rectangle(int l, int w)
{
length = l;
width = w;
}
public int area()
{
return length * width;
}
public void display()
{
string line = "";
for (int i = 0; i < width+2; i++)
2. {
if (i == 0 || i == width+1)
{
for (int j = 0; j < length*2; j++)
{
line = line + "-";
}
Console.WriteLine(line);
line = "";
}
else
{
for (int j = 0; j < length*2; j++)
{
if (j == 0 || j == length*2-1)
{
line=line+"|";
}
else
{
line = line+" ";
}
}
Console.WriteLine(line);
line = "";
}
}
}
}
}
2. In the main function, create two new rectangles rectangle2 and rectangle3 with different
dimensions than the first and different dimensions from each other. Print both of these rectangles
to the screen using the display function.