Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C#, I need help with this program. The Class for Rectangle must be its own separate class and include the parts below. There is

In C#, I need help with this program. The Class for Rectangle must be its own separate class and include the parts below. There is one answer for this but the Rectangle class is inside another class and does not pass the values correctly nor can it be called from Main. I'm trying to sort this out quickly as I only have a few hours to get it going. My current code is as follows:

using System; using static System.Console; using System.Linq;

namespace App { public class Program { public double width, length; public class double rectangle(double w, double l) { width = w; length = l;

}

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

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

public static void Main(string[] args) { Write("Enter the length: "); double length = Convert.ToDouble(Read());

Write("Enter the width: "); double width = Convert.ToDouble(Read());

rectangle r1 = new rectangle(width, length);

Write("Rectangle area: " + r1.CalculateArea()); WriteLine("Rectangle perimeter: " + r1.CalculatePerimeter()); } } }

Assignment Instructions

In this assignment, you'll need to create a new class that allows you to work with rectangles. Similar to the previous exercises, make sure that you run the unit tests. Not only does it make sure you pass all the logic tests, but here will make sure you've structured your class with the correct constructor and properties.

Rectangle Class Requirements

Your class should bet set up as follows:

  • Named Rectangle
  • Is public to allow access from other object and assemblies
  • Has a constructor that accepts two double parameters, length and width. Note that you can store these as fields or using the properties from the next bullet point if you choose to use auto properties.
  • Exposes two double properties, Length and Width that get set automatically from the values passed in the constructor
  • Has a CalculateArea method that takes no parameters and returns a double value containing the area of the rectangle (length * width)
  • Has a CalculatePermiter method that takes no parameters and returns a double value containing the perimeter of the rectangle (2 * length + 2 * width)

Main Program Logic

  1. Ask the user to enter the length of the rectangle.
  2. Ask the user to enter the width of the rectangle.
  3. Create a new rectangle object using the length and width captured.
  4. Print the area and perimeter of the rectangle

Sample Output

Enter the length: 4 Enter the width: 6 Rectangle area: 24 Rectangle perimeter: 20

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions