Page 285 - 6253
P. 285

for (Shape shape : shapes) {
                        shape.shapeInfo();
                        System.out.println("\tarea = " + shape.getArea());

                        if (shape instanceof IPerimeter) {
                            System.out.println("\tperimeter = " + ((IPerimeter)
            shape).getPerimeter());
                        }
                        if (shape instanceof IVolume) {
                            System.out.println("\tvolume = " + ((IVolume) shape).getVolume());
                        }
                        if (shape instanceof IVertex) {
                            System.out.println("\tnumber of vertex = " + ((IVertex)
            shape).getNumberOfVertex());
                        }
                    }
                }
            }



            Результат виконання

            This is a shape 'Square':
                   color: red, border style: dotted
                   side = 7.24
                   area = 52.4176
                   perimeter = 28.96
                   number of vertex = 4
            This is a shape 'Circle':
                   color: green, border style: solid
                   radius = 5.81
                   area = 105.994154
                   perimeter = 36.4868
            This is a shape 'Cube':
                   color: yellow, border style: dashed
                   side = 6.75
                   area = 273.375
                   perimeter = 81.0
                   volume = 307.546875
                   number of vertex = 8
            This is a shape 'Sphere':
                   color: blue, border style: solid
                   radius = 6.39
                   area = 512.8511759999999
                   volume = 1092.3730048799998























                                                              284
   280   281   282   283   284   285