Question: Question: C# Write a class Shape that contains the following: Constructor takes one argument, string name: Constructor prints Shape called created Abstract method calculateArea Method

Question: C# Write a class Shape that contains the following:

Constructor takes one argument, string name: Constructor prints Shape called created

Abstract method calculateArea

Method ToString which prints This is a shape object called

Protected field name and relevant properties for the same

Static field count which gets incremented every time a new instance of shape is created or when an instance of its derived class is created.

Add a protected filed for color and set it to Black

Write a class circle which inherits from above mentioned class shape and have additional members as below :

Constructor that takes one parameter name and prints relevant message, sets radius to default value

Constructor that takes two parameters name and radius and also prints relevant message Protected field radius and relevant properties

Create a protected field for color by hiding base class color (using new keyword) and set its value to Blue, create relevant properties for this field

Implementation for method calculateArea

Override ToString method to print message: This is a Circle object called whose radius is and area is and of color

Write a class rectangle which inherits from above mentioned class shape and have additional members as below:

Constructor that takes one parameter name and prints relevant message, sets width and length to default value

Constructor that takes three parameters name, length and width and also prints relevant message

Protected fields length, width and relevant properties

Create a protected field for color by hiding base class color (using new keyword) and set its value to Red , create relevant properties for this field

Implementation for method calculateArea

Override ToString method to print: "This is a Rectangle object called whose length is and width is and area is of color

Use the following for the Main() method for your program:

Circle circleA = new Circle();

Circle circleB = new Circle("Circle-B");

Circle circleC = new Circle("Circle-C", 5);

Rectangle rectangleA = new Rectangle();

Rectangle rectangleB = new Rectangle("Rectangle-B");

Rectangle rectangleC = new Rectangle("Rectangle-C", 5, 8);

Square squareA = new Square();

Square squareB = new Square("Square-B");

Square squareC = new Square("Square-C", 5);

Console.WriteLine();

Console.WriteLine(circleA);

Console.WriteLine(circleB);

Console.WriteLine(circleC);

Console.WriteLine(rectangleA);

Console.WriteLine(rectangleB);

Console.WriteLine(rectangleC);

Console.WriteLine(squareA);

Console.WriteLine(squareB);

Console.WriteLine(squareC);

Console.WriteLine();

Console.WriteLine(circleA.Name + "\t" + circleA.Radius + " has area: " + circleA.calculateArea() + "\t" + circleA.Color);

Console.WriteLine(circleB.Name + "\t" + circleB.Radius + " has area: " + circleB.calculateArea() + "\t" + circleB.Color);

Console.WriteLine(circleC.Name + "\t" + circleC.Radius + " has area: " + circleC.calculateArea() + "\t" + circleC.Color);

Console.WriteLine(rectangleA.Name + "\t" + rectangleA.Width + "\t" + rectangleA.Length + " has area: " + rectangleA.calculateArea() + "\t" + rectangleB.Color);

Console.WriteLine(rectangleB.Name + "\t" + rectangleB.Width + "\t" + rectangleB.Length + " has area: " + rectangleB.calculateArea() + "\t" + rectangleB.Color);

Console.WriteLine(rectangleC.Name + "\t" + rectangleC.Width + "\t" + rectangleC.Length + " has area: " + rectangleC.calculateArea() + "\t" + rectangleC.Color);

Console.WriteLine(squareA.Name + "\t" + squareA.Width + " has area: " + squareA.calculateArea() + "\t" + squareA.Color);

Console.WriteLine(squareB.Name + "\t" + squareB.Width + " has area: " + squareB.calculateArea() + "\t" + squareB.Color);

Console.WriteLine(squareC.Name + "\t" + squareC.Width + " has area: " + squareC.calculateArea() + "\t" + squareC.Color);

Console.Read();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!