//write a method to create and return a BadRectangle static BadRectangle CreateBadRectangle(int length, int width) { BadRectangle badRectangle = new BadRectangle(); badRectangle.width = width; badRectangle.length = length; return(badRectangle); }
static void Main(string[] args) { BadRectangle bigRectangle = new BadRectangle(); bigRectangle.length = 8; bigRectangle.width = 5; DescribeRectangle(bigRectangle); BadRectangle smallRectangle = new BadRectangle() { length = 3, width = 2 }; DescribeRectangle(smallRectangle); }
static void Main(string[] args) { //declare a BadRectangle variable BadRectangle bigRectangle; //initialized the above variable bigRectangle = new BadRectangle(); bigRectangle.length = 8; bigRectangle.width = 5; DescribeRectangle(bigRectangle); BadRectangle smallRectangle = new BadRectangle() { length = 3, width = 2 }; DescribeRectangle(smallRectangle); }
static void Main(string[] args) { //declare our object BadRectangle bigRectangle; //initialized the above object bigRectangle = new BadRectangle(); //set the two properties of the object bigRectangle.length = 8; bigRectangle.width = 5; DescribeRectangle(bigRectangle); BadRectangle small = new BadRectangle() { length = 3, width = 2 }; DescribeRectangle(small); }
static void Main(string[] args) { //declare and initialize a BadRectangle object BadRectangle r1 = new BadRectangle(); //set the length to 8 r1.length = 8; //set the width to 5 r1.width = 5; //call the CalculateAndDisplayArea method CalculateAndDisplayArea(r1); //call the CreateBadRectangle method BadRectangle r2 = CreateBadRectangle(5, 2); CalculateAndDisplayArea(r2); //call the DescribeBadRectangle method DescribeBadRectangle(r1); DescribeBadRectangle(r2); }
static void DescribeRectangle(BadRectangle rect) { Console.WriteLine($"Length: {rect.length} width:{rect.width}, area:{rect.length * rect.width}"); }
//write the method DescribeBadRectangle static void DescribeBadRectangle(BadRectangle badRectangle) { Console.WriteLine($"Width:{badRectangle.width}, length:{badRectangle.length}"); }
//create a method to calculate and display the area of an object static void CalculateAndDisplayArea(BadRectangle badRectangle) { int area = badRectangle.length * badRectangle.width; Console.WriteLine($"Area: {area}"); }