107 325
Assignments Done
98.9%
Successfully Done
In March 2023

Question #1581
Want to write a C# progm creating a Rectangle class to have two variables length and width. Two constructors are needed, the default constructor should intialize length and width to 1.0 each. The second must pass in two values to initialize length and width. There must be six methods to do the following: SetLength,SetWidth,GetLength,GetWidth, GetArea, and GetPerimeter.The perimeter is the sum of all sides of a rectangle. Three instances of the Rectangle needs to be created. The first rectOne must use the se
1
2011-03-07T09:14:33-0500
using System;namespace Application
{
public class Rectangle
{
private double length;
private double width;

public Rectangle ()
{
length = 1.0;
width = 1.0;
}

public Rectangle (double l,double w)
{
length = l;
width = w;
}

public void SetLength(double l){
length = l;
}

public void SetWidth(double w){
width = w;
}

public double GetLength(){
return length;
}

public double GetWidth(){
return width;
}

public double GetArea(){
return length*width;
}

public double GetPerimeter(){
return (length+width)*2;
}

static void Main(string[] args){
Rectangle rectOne = new Rectangle();
Console.WriteLine(&quot;Area: &quot;+rectOne.GetArea());
Console.WriteLine(&quot;Perimeter: &quot;+rectOne.GetPerimeter());
Rectangle rectTwo = new Rectangle(2.0,4.0);
Console.WriteLine(&quot;Area: &quot;+rectTwo.GetArea());
Console.WriteLine(&quot;Perimeter: &quot;+rectTwo.GetPerimeter());
Rectangle rectThree = new Rectangle(5.0,10.0);
Console.WriteLine(&quot;Area: &quot;+rectThree.GetArea());
Console.WriteLine(&quot;Perimeter: &quot;+rectThree.GetPerimeter());
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Assignment Expert
21.06.11, 16:29

You are always welcome!

Assignment Expert
21.06.11, 16:24

We have a lot of experts ready for helping you.

Assignment Expert
21.06.11, 16:22

Welcome))