Question

I've seen this one done as a console application, however I need some help setting it...

I've seen this one done as a console application, however I need some help setting it up as a windows form app using micrsoft visual c#.

C# project - Create an application named ShapesDemo that creates several objects that descend from an abstract class called GeometricFigure. Each GeometricFigure includes a height, a width, and an area. Provide get and set accessors for each field except area; the area is computed and is read-only. Include an abstract method calledComputeArea() that computes the area of the geometricFigure. Create three additional classes:

a. A Rectangle is a GeometricFigure whose area is determined by multiplying width by height.

b. A Square is a Rectangle in which the width and height are the same. Provide a constructor that accepts both height and width, forcing them to be equal if they are not. Provide a second constructor that accepts just one dimension and uses it for both height and width. The Square class uses the Rectangle’s ComputeArea() method.

c. A Triangle is a GeometricFigure whose area is determined by multiplying the width by half the height.

In the ShapesDemo class, after each object is created, pass it to a method that accepts a GeometricFigure argument in which the figure’s data is displayed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ShapesDemo
{
    abstract class GeometricFigure
    {
        static void Main(string[] args)
        {
            Rectangle rectangle = new Rectangle(8, 8);
            Square square = new Square(8, 8);
            // DisplayFigureResults(square);
            Triangle triangle = new Triangle();
            //Console.WriteLine("The Area is:", rectangle.ToString());
            Console.WriteLine("The Area is: {0}", rectangle.ComputeArea().ToString());
        }
        public int height;
        public int width;
        //public readonly double area;
        public int heigth
        {
            get { return height; }
            set { height = value; }
        }
        public int Width
        {
            get { return width; }
            set { width = value; }
        }
        // public double area
        // { get { return area; } }
        public abstract double ComputeArea();
        private static void DisplayFigureDetails(GeometricFigure shape)
        { }
    }
    class Rectangle : GeometricFigure
    {
        protected int p;
        protected int p_2;
        //private int p;
        //private int p_2;
        //added
        public Rectangle()
        {
        }
        public Rectangle(int p, int p_2)
        {
            // TODO: Complete member initialization
            this.p = p;
            this.p_2 = p_2;
        }
        public override double ComputeArea()
        {
            //Console.WriteLine("The Area is" + width.ToString(), height.ToString());
            //return width * height;
            return p * p_2;
        }
    }
    class Square : Rectangle
    {
        //private int p;
        //private int p_2;
        public Square(int p, int p_2)
        {
            // TODO: Complete member initialization
            this.p = p;
            this.p_2 = p_2;
        }
        private static void DisplayFigureDetails(GeometricFigure Square) { }
        public void equal(int height, int width)
        {
            if (height.Equals(width))
                Console.WriteLine("{0} for {1} has the same messers " +
                height, width);
        }
    }
    class Triangle : GeometricFigure
    {
        private static void DisplayFigureDetails(GeometricFigure Triangle) { }
        public override double ComputeArea()
        {
            return width * (height / 2);
        }
    }
}

PLease rate my answer!!

Add a comment
Know the answer?
Add Answer to:
I've seen this one done as a console application, however I need some help setting it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class...

    ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...

  • Create a program that calculates the area of various shapes. Console Specifications Create an abstract class...

    Create a program that calculates the area of various shapes. Console Specifications Create an abstract class named Shape. This class should contain virtual member function named get_area() that returns a double type. Create a class named Circle that inherits the Shape class and contains these constructors and member functions: Circle(double radius) double get_radius() void set_radius(double radius) double get_area() Create a class named Square that inherits the Shape class and contains these constructors and member functions: Square(double width) double get_width() void...

  • Design a console application that will print the final result obtained by a student with the...

    Design a console application that will print the final result obtained by a student with the weighting of each module. Make use of an abstract class named Student that contains variables to store the student number, test result, assignment result and exam. Create a constructor that accepts the student number, test result, assignment result and the exam result as parameters and create get methods for the variables. The Student class must implement an iReport interface that contains the following: public...

  • This exercise guides you through the process of converting an Area and Perimeter application from a...

    This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...

  • Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The clas...

    Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...

  • PLEASE HELP this is the last part of my lab and I need help ): add comments please (: if it is to...

    PLEASE HELP this is the last part of my lab and I need help ): add comments please (: if it is too difficult you do not have to do part 3 but it would be greatly appreciated if you do ! Obtain example code files Circle.java, Shape.java, CircleShape2.java, Sphere.java, and CircleShapeApp.java from the downloaded files in Ch8. Compile and execute the example and understand the polymorphism it performs. (I have copied and pasted all of these files below) Modify...

  • I need some help i need to do this in C# Objectives: • Create an application...

    I need some help i need to do this in C# Objectives: • Create an application that uses a dictionary collection to store information about an object. • Understanding of abstract classes and how to use them • Utilize override with an abstract class • Understanding of Interfaces and how to use them • Implement an Interface to create a “contract” between classes. • Compare and contrast inheritance and interfaces. Instructions: Interface: Create an interface called ITrainable which contains the...

  • /*hello everyone. my question is mostly related to the garagetest part of this assignment that i've...

    /*hello everyone. my question is mostly related to the garagetest part of this assignment that i've been working on. i am not sure how to read the file's contents AND put them into variables/an array. should it be in an arraylist? or maybe a regular array? or no arrays at all? i am also not sure how to call the factory method from garagec. i'm thinking something along the lines of [Garage garage = new GarageC.getInstance("GarageC", numFloors, areaofEachFloor);] but i...

  • Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume...

    Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume of rectangular objects. First, write an abstract super class RectangularShape, then write a subclass Rectangle that inherits from the super class to compute areas of rectangles, including squares if there is only one data. Finally, write another subclass Cuboid that inherits from its super class Rectangle above to compute surface areas and volumes of cuboids, including 3 equal sided cube. Must apply code-reusability in...

  • Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve...

    Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT