{
private double x, y, z;
{
this(0.0, 0.0, 0.0);
}
public Shape(double x,
double y,
double z
) {
this.x = x;
this.y = y;
this.z = z;
}
public void show()
{
System.
out.
println("中心座標: (" + x
+ "," + y
+ "," + z
+ ")"); }
public void move(double dx, double dy, double dz)
{
x += dx;
y += dy;
z += dz;
}
public void scale(double k)
{
x *= k;
y *= k;
z *= k;
}
}
class Sphere
extends Shape {
private double radius = 0.0;
public Sphere()
{
super();
}
public Sphere(double x, double y, double z)
{
super(x, y, z);
}
@Override
public void show()
{
super.show();
System.
out.
println("半径:" + radius
); }
@Override
public void scale(double k)
{
super.scale(k);
}
}
class ShapeEx
{
public static void main
(String[] args
) {
shapes
[1] = new Shape(1.1,
2.2,
3.3); shapes[2] = new Sphere();
shapes[3] = new Sphere(4.4, 5.5, 6.6);
for (Shape shape
: shapes
) {
shape.show();
shape.move(1.0, 1.0, 1.0);
shape.show();
shape.scale(2.0);
shape.show();
}
}
}
Y2xhc3MgU2hhcGUKewoJcHJpdmF0ZSBkb3VibGUgeCwgeSwgejsKCQoJcHVibGljIFNoYXBlKCkKCXsKCQl0aGlzKDAuMCwgMC4wLCAwLjApOwoJfQoJCglwdWJsaWMgU2hhcGUoZG91YmxlIHgsIGRvdWJsZSB5LCBkb3VibGUgeikKCXsKCQl0aGlzLnggPSB4OwoJCXRoaXMueSA9IHk7CgkJdGhpcy56ID0gejsKCX0KCQoJcHVibGljIHZvaWQgc2hvdygpCgl7CgkJU3lzdGVtLm91dC5wcmludGxuKCLkuK3lv4PluqfmqJk6ICgiICsgeCArICIsIiArIHkgKyAiLCIgKyB6ICsgIikiKTsKCX0KCQoJcHVibGljIHZvaWQgbW92ZShkb3VibGUgZHgsIGRvdWJsZSBkeSwgZG91YmxlIGR6KQoJewoJCXggKz0gZHg7CgkJeSArPSBkeTsKCQl6ICs9IGR6OwoJfQoJCglwdWJsaWMgdm9pZCBzY2FsZShkb3VibGUgaykKCXsKCQl4ICo9IGs7CgkJeSAqPSBrOwoJCXogKj0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座標: (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