Exemple #1
0
        public void RunTriangle()
        {
            Console.WriteLine();
            Console.Write("Enter the height of the triangle: ");
            try
            {
                triangle1.Height = Convert.ToDouble(Console.ReadLine());
            }
            catch (OverflowException)
            {
                Console.WriteLine("Must be a positive number");
            }

            Console.WriteLine();
            Console.Write("Enter the base length of the triangle: ");
            try
            {
                triangle1.BaseLength = Convert.ToDouble(Console.ReadLine());
            }
            catch (OverflowException)
            {
                Console.WriteLine("Must be a positive number");
            }

            Console.Write(Environment.NewLine + "The area of the triangle1 is: {0}", triangle1.GetArea());
            Console.Write(Environment.NewLine + "The perimeter of triangle1 is {0}", triangle1.GetPerimeter());
        }
Exemple #2
0
        private void btnResultTriang_Click(object sender, EventArgs e)
        {
            Shape triangle = new Triangle(float.Parse(tbSideATriang.Text), float.Parse(tbSideBTriang.Text),
                                          float.Parse(tbSideCTriang.Text));

            lbPerymTriang.Text = "Perimetr is " + triangle.GetPerimeter();
            lbAreaTriang.Text  = "Area is " + triangle.GetArea();
        }
Exemple #3
0
        public void Run()
        {
            Triangle triangleOne = new Triangle();

            Console.WriteLine("Enter the height of the triangle: ");
            triangleOne.Height = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Enter the base length of the triangle: ");
            triangleOne.BaseLength = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("The area of the triangle is " + triangleOne.GetArea());
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Circle    circle    = new Circle(8.08);
            Triangle  triangle  = new Triangle(17.2, 17.94, 14);
            Rectangle rectangle = new Rectangle(9.86, 15.11);

            Console.WriteLine("Enter number of shape, tnat need to calculate area and perimeter:\n1. Circle\n2. Triangle\n3. Rectangle");
            int maxNumber   = 3;
            int inputNumber = 0;

            while (true)
            {
                try
                {
                    inputNumber = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
                if (0 < inputNumber && inputNumber < (maxNumber + 1))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Wrong number");
                }
            }
            switch (inputNumber)
            {
            case 1:
                Console.WriteLine($"Perimetr of circle = {circle.GetPerimeter()}");
                Console.WriteLine($"Area of circle = {circle.GetArea()}");
                break;

            case 2:
                Console.WriteLine($"Perimetr of Triangle = {triangle.GetPerimeter()}");
                Console.WriteLine($"Area of Triangle = {triangle.GetArea()}");
                break;

            case 3:
                Console.WriteLine($"Perimetr of Rectangle = {rectangle.GetPerimeter()}");
                Console.WriteLine($"Area of Rectangle = {rectangle.GetArea()}");
                break;
            }
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // Rectangle
            Rectangle rect1 = new Rectangle("Blue", 3, 5);

            Console.WriteLine("\nrect1 Area: " + rect1.GetArea());
            Console.WriteLine("rect1 Perimeter: " + rect1.GetPerimeter());
            Console.WriteLine("rect1 Length: " + rect1.GetLength());
            rect1.SetColor("Magenta");
            Console.WriteLine(rect1.GetColor());
            rect1.SetWidth(5);

            // Circle
            Circle circ1 = new Circle("Red", 4);

            Console.WriteLine("\ncirc1 Area: " + circ1.GetArea());
            Console.WriteLine("circ1 Circumference: " + circ1.GetPerimeter());
            Console.WriteLine("circ1 Radius: " + circ1.GetRadius());
            circ1.SetColor("Lime Green");
            Console.WriteLine(circ1.GetColor());
            circ1.SetRadius(8);

            // Square
            Square sqr1 = new Square("White", 2);

            Console.WriteLine("\nsqr1 Area: " + sqr1.GetArea());
            Console.WriteLine("sqr1 Perimeter: " + sqr1.GetPerimeter());
            Console.WriteLine("sqr1 Side: " + sqr1.GetSide());
            sqr1.SetColor("Cyan");
            Console.WriteLine(sqr1.GetColor());
            sqr1.SetSide(5);

            // Triangle
            Triangle tri1 = new Triangle("Black", 3, 5, 7);

            Console.WriteLine("\ntri1 Area: " + tri1.GetArea());
            Console.WriteLine("tri1 Perimeter: " + tri1.GetPerimeter());
            Console.WriteLine("tri1 SideA: " + tri1.GetSideA());
            tri1.SetColor("Lilac");
            Console.WriteLine(tri1.GetColor());
            tri1.SetSideC(5);

            // Hexagon
            Hexagon hex1 = new Hexagon(2);

            Console.WriteLine("\nhex1 Area: " + hex1.GetArea());
            Console.Write("hex1 Perimeter: " + hex1.GetPerimeter());
        }
Exemple #6
0
        public void Run()
        {
            Triangle triangle1 = new Triangle();

            Console.WriteLine("Enter the height of the triangle: ");
            double height = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Enter the base length of the triangle: ");
            double baseLength = Convert.ToDouble(Console.ReadLine());

            triangle1.Height     = height;
            triangle1.BaseLength = baseLength;

            Console.Write("The area of the triangle is ");
            Console.WriteLine(triangle1.GetArea());
        }
        static void Main(string[] args)
        {
            Square square1 = new Square(5);

            double area = square1.GetArea();

            Console.WriteLine(area);
            double perimeter = square1.GetPerimeter();

            Console.WriteLine(perimeter);
            square1.Setside(15);
            double sideValue = square1.GetSide();

            Console.WriteLine(sideValue);

            Circle circle1 = new Circle(2);

            double areaCircle = circle1.GetArea();

            Console.WriteLine(areaCircle);
            double circumferenceCircle = circle1.GetCircumference();

            Console.WriteLine(circumferenceCircle);
            circle1.SetRadius(15);
            double radiusValue = circle1.GetRadius();

            Console.WriteLine(radiusValue);

            Triangle triangle1 = new Triangle(2, 3, 5);

            double areatriangle = triangle1.GetArea();

            Console.WriteLine(areatriangle);
            double perimetertriangle = triangle1.GetPerimeter();

            Console.WriteLine(perimetertriangle);
            triangle1.SetSideA(10);
            Console.WriteLine(triangle1.GetSideA());
        }
Exemple #8
0
        public void Run()
        {
            Triangle triangle1 = new Triangle();
            Triangle triangle2 = new Triangle(3, 4);

            Console.WriteLine("Enter the height of the triangle: ");
            try
            {
                triangle1.Height = Convert.ToDouble(Console.ReadLine());
            }
            catch (OverflowException)
            {
                Console.WriteLine("Must be a positive number ");
            }


            Console.WriteLine("Enter the base length of the triangle: ");
            try
            {
                triangle1.Baselength = Convert.ToDouble(Console.ReadLine());
            }
            catch (OverflowException)
            {
                Console.WriteLine("Must be a positive number ");
            }

            Console.Write("The area of the triangle1 is ");
            Console.WriteLine(triangle1.GetArea());

            Console.Write("The area of the triangle2 is ");
            Console.WriteLine(triangle2.GetArea());

            Console.Write("The perimeter of the triangle1 is ");
            Console.WriteLine(triangle1.GetPerimeter());

            Console.Write("The perimeter of the triangle2 is ");
            Console.WriteLine(triangle2.GetPerimeter());
        }
Exemple #9
0
 public override double GetArea()
 {
     return(FirstTriangle.GetArea() * 2);
 }