Skip to content

4.7 Code for the Shape class

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace Geometry.Models
{
    public class Shape
    {
        protected const double LimitValueForBigShape = 100.0;
        protected const string DefaultColor = "white";

        protected string _color;

        public string Color
        {
            get => _color;
            set => _color = value;
        }

        public Shape(string color)
        {
            _color = color;
        }

        public Shape() : this(DefaultColor)
        {
        }

        public string DescribeSize()
        {
            if (CalculateArea() > LimitValueForBigShape)
                return "I am big!!!";
            else
                return "I am small!!!";
        }

        public virtual double CalculateArea()
        {
            return 0;
        }

        public virtual double CalculatePerimeter()
        {
            return 0;
        }

        public static string Definition()
        {
            return "A shape is a collection of points.";
        }
    }
}