Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello i need help with a previous tutors help im doing an oop assingment its run by the programming language c# i need help putting

Hello i need help with a previous tutors help im doing an oop assingment its run by the programming language c#

i need help putting this code in

private void DisplayArea(Shape shape)
{
    listBox1.Items.Add("Area: " + shape.Area);
    MessageBox.Show("Area: " + shape.Area);
}
 

i followed the steps but have no clue exactly where the above code goes, please show an example of it and show that it works thank you!

 

 

 

 

Here are the steps to complete this assignment in C# using Visual Studio:

Open Visual Studio and create a new Windows Forms App project.
Add a ListBox control to the form by dragging it from the Toolbox onto the form.
Create an abstract class called Shape by right-clicking on the project in Solution Explorer, selecting Add, and then selecting Class. In the new class file, add the following code:
 

public abstract class Shape
{
    private static int shapeCount = 0;

    public static int ShapeCount
    {
        get { return shapeCount; }
    }

    public abstract double Area { get; }

    protected Shape()
    {
        shapeCount++;
    }
}
Create a class called Circle that inherits from Shape. In the same class file as Shape, add the following code:

 

public class Circle : Shape
{
    private double radius;

    public Circle(double radius)
    {
        this.radius = radius;
    }

    public double Radius
    {
        get { return radius; }
    }

    public double Diameter
    {
        get { return radius * 2; }
    }

    public override double Area
    {
        get { return Math.PI * radius * radius; }
    }

    public void ChangeRadius(double newRadius)
    {
        radius = newRadius;
    }
}
Create a class called Rectangle that inherits from Shape. In the same class file as Shape, add the following code:

 

public class Rectangle : Shape
{
    private double length;
    private double width;

    public Rectangle(double length, double width)
    {
        this.length = length;
        this.width = width;
    }

    public double Length
    {
        get { return length; }
    }

    public double Width
    {
        get { return width; }
    }

    public override double Area
    {
        get { return length * width; }
    }
}
In the form's class file, add the following method:

 

private void DisplayArea(Shape shape)
{
    listBox1.Items.Add("Area: " + shape.Area);
    MessageBox.Show("Area: " + shape.Area);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To incorporate the DisplayArea method into your code you need to follow these steps 1 Open your Wind... 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_2

Step: 3

blur-text-image_3

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

Systems analysis and design

Authors: Alan Dennis, Barbara Haley Wixom, Roberta m. Roth

5th edition

978-1118057629, 1118057627, 978-111880817

More Books

Students also viewed these Programming questions