static void Main(string[] args)
        {
            Console.Title = "计算球、圆柱和圆锥的体积";

            Ball ball = new Ball(10);                               //实例化球体
            Console.WriteLine("半径为{0}的球体体积为{1:0.00}", ball.Radius, ball.Volume);
            Circle cylinder = new Cylinder(10, 10);                 //实例化圆柱体
            Console.WriteLine("半径为{0}高度为{1}的圆柱体体积为{2:F3}", cylinder.Radius, 10, cylinder.Volume);
            Circle cone = new Cone(10, 10);                         //实例化圆锥体
            Console.WriteLine("半径为{0}高度为{1}的圆柱体体积为{2:#,#.#}", cone.Radius, 10, cone.Volume);

            Console.ReadLine();
        }
示例#2
0
        private static void Main()
        {
            try
            {
                Task.Do();

                Shape figure = new Parallelepiped(Color.Black, Color.Blue, 1.5, 2, 2, 2);
                Console.Out.WriteLine(string.Format("Volume of parallepiped: {0:F2}", figure.Volume()));

                figure = new Cylinder(Color.Black, Color.Blue, 2.5, 2, 3);
                Console.Out.WriteLine(string.Format("Volume of cylinder: {0:F2}", figure.Volume()));
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
示例#3
0
        public static void Assignment7()
        {
            Random random = new Random();
            int n = 100;
            I3DObject[] objects = new I3DObject[n];
            for (int i = 0; i < n; i++)
            {
                switch(random.Next(3))
                {
                    case 0:
                        objects[i] = new Box(random.NextDouble(), random.NextDouble(), random.NextDouble());
                        break;
                    case 1:
                        objects[i] = new Cylinder(random.NextDouble(), random.NextDouble());
                        break;
                    case 2:
                        objects[i] = new Sphere(random.NextDouble());
                        break;
                }
            }

            I3DObject largest = objects.OrderByDescending(o => o.Volume).FirstOrDefault();
            Console.WriteLine("Largest shape: {0} ({1}m^3)", largest.GetType(), largest.Volume);
            Console.WriteLine("Total volume of all shapes: {0}", objects.Sum(o => o.Volume));
        }