fork download
  1. class Shape
  2. {
  3. private double x, y, z;
  4.  
  5. public Shape()
  6. {
  7. this(0.0, 0.0, 0.0);
  8. }
  9.  
  10. public Shape(double x, double y, double z)
  11. {
  12. this.x = x;
  13. this.y = y;
  14. this.z = z;
  15. }
  16.  
  17. public void show()
  18. {
  19. System.out.println("中心座標: (" + x + "," + y + "," + z + ")");
  20. }
  21.  
  22. public void move(double dx, double dy, double dz)
  23. {
  24. x += dx;
  25. y += dy;
  26. z += dz;
  27. }
  28.  
  29. public void scale(double k)
  30. {
  31. x *= k;
  32. y *= k;
  33. z *= k;
  34. }
  35. }
  36.  
  37. class Sphere extends Shape
  38. {
  39. private double radius = 0.0;
  40.  
  41. public Sphere()
  42. {
  43. super();
  44. }
  45.  
  46. public Sphere(double x, double y, double z)
  47. {
  48. super(x, y, z);
  49. }
  50.  
  51. @Override
  52. public void show()
  53. {
  54. super.show();
  55. System.out.println("半径:" + radius);
  56. }
  57.  
  58. @Override
  59. public void scale(double k)
  60. {
  61. super.scale(k);
  62. }
  63. }
  64.  
  65. class ShapeEx
  66. {
  67. public static void main (String[] args)
  68. {
  69. Shape[] shapes = new Shape[4];
  70.  
  71. shapes[0] = new Shape();
  72. shapes[1] = new Shape(1.1, 2.2, 3.3);
  73. shapes[2] = new Sphere();
  74. shapes[3] = new Sphere(4.4, 5.5, 6.6);
  75.  
  76. for (Shape shape : shapes)
  77. {
  78. shape.show();
  79. shape.move(1.0, 1.0, 1.0);
  80. shape.show();
  81. shape.scale(2.0);
  82. shape.show();
  83. }
  84. }
  85. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
中心座標: (0.0,0.0,0.0)
中心座標: (1.0,1.0,1.0)
中心座標: (2.0,2.0,2.0)
中心座標: (1.1,2.2,3.3)
中心座標: (2.1,3.2,4.3)
中心座標: (4.2,6.4,8.6)
中心座標: (0.0,0.0,0.0)
半径:0.0
中心座標: (1.0,1.0,1.0)
半径:0.0
中心座標: (2.0,2.0,2.0)
半径:0.0
中心座標: (4.4,5.5,6.6)
半径:0.0
中心座標: (5.4,6.5,7.6)
半径:0.0
中心座標: (10.8,13.0,15.2)
半径:0.0