Exemplo n.º 1
0
        public static void TestShapes()
        {
            string str = null;

            Console.WriteLine("Hello World!");
            Ellipse ellipse2 = new Ellipse(5.7, 34.5);

            //TODO : Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
            //Console.WriteLine(ellipse2.ToString(null));
            //Console.WriteLine(ellipse2.ToString(str));
            Console.WriteLine(ellipse2.ToString("R"));
            Console.WriteLine(ellipse2.ToString("G"));
            Console.WriteLine("\n");

            Rectangle rec = new Rectangle(5.7, 34.5);

            Console.WriteLine(rec.ToString("R"));
            Console.WriteLine(rec.ToString("G"));
            Console.WriteLine("\n");

            Cuboid cub = new Cuboid(29.6, 29.6, 29.6);

            Console.WriteLine(cub.ToString("R"));
            Console.WriteLine(cub.ToString("G"));
            Console.WriteLine("\n");

            Cylinder cyl = new Cylinder(29.6, 29.6, 29.6);

            Console.WriteLine(cyl.ToString("R"));
            Console.WriteLine(cyl.ToString("G"));
            Console.WriteLine("\n");

            Sphere sphere = new Sphere(29.6);

            //Test bad value
            //Console.WriteLine(sphere.ToString("BADVALUE"));
            Console.WriteLine(sphere.ToString("R"));
            Console.WriteLine(sphere.ToString("G"));
            Console.WriteLine("\n");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            char input;

            List <Shape> Shapes = new List <Shape>();

            while (true)
            {
                Console.WriteLine("A - Rectangle \n" +
                                  "B - Square \n" +
                                  "C - Box \n" +
                                  "D - Cube \n" +
                                  "E - Ellipse \n" +
                                  "F - Circle \n" +
                                  "G - Cylinder \n" +
                                  "H - Sphere \n" +
                                  "I - Triangle \n" +
                                  "J - Tetrahedron \n " +
                                  "\n0 - List all shapes and Exit      (" + Shapes.Count + " Size)");

                input = Char.Parse(Console.ReadLine());

                switch (input)
                {
                case 'A':
                case 'a':
                    var newRectangle = new Rectangle();
                    newRectangle.SetData();
                    Shapes.Add(newRectangle);
                    break;

                case 'B':
                case 'b':
                    var newSquare = new Square();
                    newSquare.SetData();
                    Shapes.Add(newSquare);
                    break;

                case 'C':
                case 'c':
                    var newBox = new Box();
                    newBox.SetData();
                    Shapes.Add(newBox);
                    break;

                case 'D':
                case 'd':
                    var newCube = new Cube();
                    newCube.SetData();
                    Shapes.Add(newCube);
                    break;

                case 'E':
                case 'e':
                    var newEllipse = new Ellipse();
                    newEllipse.SetData();
                    Shapes.Add(newEllipse);
                    break;

                case 'F':
                case 'f':
                    var newCircle = new Circle();
                    newCircle.SetData();
                    Shapes.Add(newCircle);
                    break;

                case 'G':
                case 'g':
                    var newCylinder = new Cylinder();
                    newCylinder.SetData();
                    Shapes.Add(newCylinder);
                    break;

                case 'H':
                case 'h':
                    var newSphere = new Sphere();
                    newSphere.SetData();
                    Shapes.Add(newSphere);
                    break;

                case 'I':
                case 'i':
                    var newTriangle = new Triangle();
                    newTriangle.SetData();
                    Shapes.Add(newTriangle);

                    break;

                case 'J':
                case 'j':
                    var newTetrahedron = new Tetrahedron();
                    newTetrahedron.SetData();
                    Shapes.Add(newTetrahedron);

                    break;

                case '0':

                    foreach (Shape temp in Shapes)
                    {
                        Console.WriteLine(temp.ToString());
                    }
                    Console.Read();

                    break;
                }



                Console.Clear();
            }
        }