class Shape {}
class Point extends Shape {
protected float x,y;
Point (float x, float y) { this.x=x; this.y=y; }
public String toString () {
return "("+x+","+y+")";
}
void move (float dx, float dy) { x += dx; y += dy; }
}
class Rectangle extends Point {
protected float height, width;
Rectangle (float x, float y, float h, float w) {
super (x,y); height=h; width=w;
}
public String toString () {
return "("+x+","+y+";h="+height+",w="+width+")";
}
}
class Circle extends Point {
protected float radius;
Circle (float x, float y, float r) {
super (x,y); radius=r;
}
public String toString () {
return "("+x+","+y+";r="+radius+")";
}
}
class Shapes {
public static void main (String [] args) {
final Point p = new Point (2.3f, 4.5f);
final Rectangle r = new Rectangle (2.3f, 4.5f, 45.1f, 89.1f);
final Circle c = new Circle (2.3f, 4.5f, 0.3f);
r.move (3.4f, 0.0f);
c.move (-3.4f, 1.0f);
System.out.println (p);
System.out.println (r);
System.out.println (c);
}
}
Tidak ada komentar:
Posting Komentar