MiroslavKisov

GeometryCalculator

Oct 1st, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _11.GeometryCalculator
  4. {
  5.     class StartUp
  6.     {
  7.         static void Main()
  8.         {
  9.             // Choosing the figure
  10.             string typeOfFigure = Console.ReadLine();
  11.             if (typeOfFigure == "triangle")
  12.             {
  13.                 double side = double.Parse(Console.ReadLine());
  14.                 double height = double.Parse(Console.ReadLine());
  15.                 Console.WriteLine($"{GetTriangleArea(side,height):f2}");
  16.             }
  17.             else if (typeOfFigure == "rectangle")
  18.             {
  19.                 double width = double.Parse(Console.ReadLine());
  20.                 double height = double.Parse(Console.ReadLine());
  21.                 Console.WriteLine($"{GetRectangleArea(width,height):f2}");
  22.             }
  23.             else if (typeOfFigure == "square")
  24.             {
  25.                 double side = double.Parse(Console.ReadLine());
  26.                 Console.WriteLine($"{GetSquareArea(side):f2}");
  27.             }
  28.             else if (typeOfFigure == "circle")
  29.             {
  30.                 double radius = double.Parse(Console.ReadLine());
  31.                 Console.WriteLine($"{GetCircleArea(radius):f2}");
  32.             }
  33.         }
  34.         // Calculating the area of the triangle.
  35.         public static double GetTriangleArea(double side, double height)
  36.         {
  37.             double triangleArea = side * height / 2;
  38.             return triangleArea;
  39.         }
  40.         // Calculating the area of the rectangle.
  41.         public static double GetRectangleArea(double width,double height)
  42.         {
  43.             double rectangleArea = width * height;
  44.             return rectangleArea;
  45.         }
  46.         // Calculating the area of the square.
  47.         public static double GetSquareArea(double side)
  48.         {
  49.             double areaSquare = side * side;
  50.             return areaSquare;
  51.         }
  52.         // Calculating the area of the circle.
  53.         public static double GetCircleArea(double radius)
  54.         {
  55.             double circleArea = Math.PI * radius * radius;
  56.             return circleArea;
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment