Example #1
0
        static void Main()
        {
            Console.Write("Enter Radius of a circle: ");
            double a      = int.Parse(Console.ReadLine());
            Circle circle = new Circle(a);

            Console.WriteLine("Circle:");
            circle.CalculateArea();
            Console.WriteLine();

            Console.Write("Enter Width of a Rectangle: ");
            double b = int.Parse(Console.ReadLine());

            Console.Write("Enter Height of a Rectangle: ");
            double    c    = int.Parse(Console.ReadLine());
            Rectangle rect = new Rectangle(b, c);

            Console.WriteLine("Rectangle:");
            rect.CalculateArea();
            rect.CalculatePerimeter();
            Console.WriteLine();

            Console.Write("Enter Width of a Rhombus: ");
            double d = int.Parse(Console.ReadLine());

            Console.Write("Enter Height of a Rhombus: ");
            double  e       = int.Parse(Console.ReadLine());
            Rhombus rhombus = new Rhombus(d, e);

            Console.WriteLine("Rhombus:");
            rhombus.CalculateArea();
            rhombus.CalculatePerimeter();
            Console.WriteLine();
        }
Example #2
0
        public ActionResult Index(FigureData formData)
        {
            string dims   = formData.Dimensions;
            double result = 0;

            try
            {
                if (formData.Dimensions.Contains("."))
                {
                    dims = formData.Dimensions.Replace('.', ',');
                }
                string[] sizesArray = dims.Split(new Char[] { ';' });


                switch (formData.Shape)
                {
                case Shapes.Koło:
                    Circle circle = new Circle();
                    circle.DimR = Convert.ToDouble(sizesArray[0].Trim());
                    result      = Math.Round(circle.CalculateArea(), 2);
                    break;

                case Shapes.Kwadrat:
                    Square square = new Square();
                    square.DimA = Convert.ToDouble(sizesArray[0].Trim());
                    result      = Math.Round(square.CalculateArea(), 2);
                    break;

                case Shapes.Prostokąt:
                    Rectangle rectangle = new Rectangle();
                    rectangle.DimA = Convert.ToDouble(sizesArray[0].Trim());
                    rectangle.DimB = Convert.ToDouble(sizesArray[1].Trim());
                    result         = Math.Round(rectangle.CalculateArea(), 2);
                    break;

                case Shapes.Romb:
                    Rhombus rhombus = new Rhombus();
                    rhombus.DimA = Convert.ToDouble(sizesArray[0].Trim());
                    rhombus.DimH = Convert.ToDouble(sizesArray[1].Trim());
                    result       = Math.Round(rhombus.CalculateArea(), 2);
                    break;

                case Shapes.Równoległobok:
                    Parallelogram parallelogram = new Parallelogram();
                    parallelogram.DimA = Convert.ToDouble(sizesArray[0].Trim());
                    parallelogram.DimH = Convert.ToDouble(sizesArray[1].Trim());
                    result             = Math.Round(parallelogram.CalculateArea(), 2);
                    break;

                case Shapes.Trapez:
                    Trapezoid trapezoid = new Trapezoid();
                    trapezoid.DimA = Convert.ToDouble(sizesArray[0].Trim());
                    trapezoid.DimB = Convert.ToDouble(sizesArray[1].Trim());
                    trapezoid.DimH = Convert.ToDouble(sizesArray[2].Trim());
                    result         = Math.Round(trapezoid.CalculateArea(), 2);
                    break;

                case Shapes.Trójkąt:
                    Triangle triangle = new Triangle();
                    triangle.DimA = Convert.ToDouble(sizesArray[0].Trim());
                    triangle.DimH = Convert.ToDouble(sizesArray[1].Trim());
                    result        = Math.Round(triangle.CalculateArea(), 2);
                    break;
                }

                formData.ResultNotification = string.Format("Pole powierzchni figury {0} dla podanych wymiarów wynosi: {1}.", formData.Shape, result);
            }
            catch (NullReferenceException)
            {
                formData.ResultNotification = "Podaj wymiary figury";
            }
            catch (FormatException)
            {
                formData.ResultNotification = "Podaj prawidłowe dane";
            }
            catch (IndexOutOfRangeException)
            {
                formData.ResultNotification = "Podaj wszystkie wymagane wymiary w formacie podanym w instrukcji";
            }

            return(View(formData));
        }