Esempio n. 1
0
        static void Main(string[] args)
        {
            Circle C1 = new Circle();

            C1.radis = 5;
            Console.WriteLine("圓面積為:{0}", C1.GetArea());
            Console.Read();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("Adding new Cirlce.");
            Circle cirlce = new Circle(2.0);

            Console.WriteLine("Cirlce's radius is 2.0! Calculating it's area.");
            cirlce.GetArea();
            Console.WriteLine("Circle's area is " + cirlce.Area);
            Console.WriteLine("Adding new Triangle.");
            double[] i    = { 2, 1, 1 };
            Triangle tri1 = new Triangle(i);

            Console.WriteLine("Triangle's sides are 2, 1 and 1! Calculating it's area.");
            tri1.GetArea("sides");
            Console.WriteLine("Triangle's area is " + tri1.Area);
            Console.WriteLine("Adding new Triangle.");
            double[] о    = { 3.5, 3, 1 };
            Triangle tri3 = new Triangle(о);

            Console.WriteLine("Triangle's sides are 3.5, 3 and 1! Calculating it's area.");
            tri3.GetArea("sides");
            Console.WriteLine("Triangle's area is " + tri3.Area);
            Console.WriteLine("Adding new Triangle.");
            double[] k    = { 2, 3, 1 };
            Triangle tri2 = new Triangle(k);

            Console.WriteLine("Triangle's sides are 3, 2 and 1! Checking wheter it right-angled.");
            if (tri2.IsRightAngled())
            {
                Console.WriteLine("Sure it is!");
            }
            else
            {
                Console.WriteLine("I guess it's not.");
            }

            Console.WriteLine("Adding new Triangle.");
            double[] t    = { 2, 2.236, 1 };
            Triangle tri4 = new Triangle(t);

            Console.WriteLine("Triangle's sides are 2.24, 2 and 1! Checking wheter it right-angled.");
            if (tri4.IsRightAngled())
            {
                Console.WriteLine("Sure it is!");
            }
            else
            {
                Console.WriteLine("I guess it's not.");
            }
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            Triangle triangle = new Triangle();

            Console.WriteLine("请输入三角形的三边长:");
            String str1 = Console.ReadLine();
            String str2 = Console.ReadLine();
            String str3 = Console.ReadLine();
            double a    = Convert.ToDouble(str1);
            double b    = Convert.ToDouble(str2);
            double c    = Convert.ToDouble(str3);

            triangle.GetArea(a, b, c);
            Circle circle = new Circle();

            Console.WriteLine("请输入圆的半径:");
            String str4   = Console.ReadLine();
            double radius = Convert.ToDouble(str4);

            circle.GetArea(radius);
            Square square = new Square();

            Console.WriteLine("请输入正方形的边长:");
            String str5   = Console.ReadLine();
            double length = Convert.ToDouble(str5);

            square.GetArea(length);
            Rectangle rectangle = new Rectangle();

            Console.WriteLine("请输入长方形的长和宽:");
            String str6   = Console.ReadLine();
            String str7   = Console.ReadLine();
            double width  = Convert.ToDouble(str6);
            double height = Convert.ToDouble(str7);

            rectangle.GetArea(width, height);
            Console.ReadKey();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            WL("1 - Quadrilateral");
            WL("2 - Triangle");
            WL("3 - Circle");
            space();

            ConsoleKeyInfo Menu1;

            Menu1 = Console.ReadKey();
            ////////////////// Quadrilateral //////////////////
            if (Menu1.Key == ConsoleKey.D1)
            {
                space();
                WL("Input Color");
                space();
                string UColor = Console.ReadLine();
                space();
                WL("1 - Square");
                WL("2 - Rectangle");
                space();
                ConsoleKeyInfo Menu2;
                Menu2 = Console.ReadKey();
                ////////////////// Square //////////////////
                if (Menu2.Key == ConsoleKey.D1)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Square newSq = new Square(UColor, Uside1);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newSq.GetArea(Uside1));
                        WL("Perimeter: " + newSq.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                ////////////////// Rectangle //////////////////
                if (Menu2.Key == ConsoleKey.D2)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        WL("Input side length 2");
                        double Uside2    = double.Parse(Console.ReadLine());
                        string Uside2Str = Uside2.ToString();
                        space();
                        if (Uside2 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside2Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Rectangle newRec = new Rectangle(UColor, Uside1, Uside2);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newRec.GetArea(Uside1));
                        WL("Perimeter: " + newRec.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                Console.ReadKey();
            }
            ////////////////// Triangle //////////////////
            if (Menu1.Key == ConsoleKey.D2)
            {
                space();
                WL("Input Color");
                space();
                string UColor = Console.ReadLine();
                space();
                WL("1 - Equilateral");
                WL("2 - Right-Angled");
                space();
                ConsoleKeyInfo Menu2;
                Menu2 = Console.ReadKey();
                //////////////////  Equilateral //////////////////
                if (Menu2.Key == ConsoleKey.D1)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Equilateral newEq = new Equilateral(UColor, Uside1);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newEq.GetArea(Uside1));
                        WL("Perimeter: " + newEq.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                ////////////////// Right-Angled //////////////////
                if (Menu2.Key == ConsoleKey.D2)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        WL("Input side length 2");
                        double Uside2    = double.Parse(Console.ReadLine());
                        string Uside2Str = Uside2.ToString();
                        space();
                        if (Uside2 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside2Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        RightAngled newRA = new RightAngled(UColor, Uside1, Uside2);
                        newRA.SetHypotenuse(Uside1, Uside2);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newRA.GetArea(Uside1));
                        WL("Perimeter: " + newRA.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                Console.ReadKey();
            }
            ////////////////// Circle //////////////////
            if (Menu1.Key == ConsoleKey.D3)
            {
                try
                {
                    space();
                    WL("Input Color");
                    space();
                    string UColor = Console.ReadLine();
                    space();
                    WL("Input radius");
                    double URad    = double.Parse(Console.ReadLine());
                    string URadStr = URad.ToString();
                    int    d;
                    if (URad < 1)
                    {
                        throw (new InvalidIntException(""));
                    }
                    if (!int.TryParse(URadStr, out d))
                    {
                        throw (new InvalidDecException(""));
                    }
                    space();
                    Circle newCirc = new Circle(UColor, URad);
                    space();
                    WL("Color: " + UColor);
                    WL("Area: " + newCirc.GetArea(URad));
                    WL("Circumference: " + newCirc.GetPerimeter(URad));
                }
                catch (InvalidIntException e)
                {
                    space();
                    WL(e.Message);
                }
                catch (InvalidDecException e)
                {
                    space();
                    WL(e.Message);
                }
                finally
                {
                    WL("Thanks for using the app!");
                }
            }
            Console.ReadKey();
        }