fork download
  1. public class Main {
  2. public static void log(Object... o) {
  3. String s = "";
  4. for (int i=0; i<o.length; i++) { s += o[i] + " "; }
  5. System.out.println(s);
  6. }
  7.  
  8. public static void main(String[] args) {
  9. new Main();
  10. }
  11. public Main() {
  12. Shape[] shapes = new Shape[3];
  13. shapes[0] = new Circle(100, 100, 20);
  14. Circle c = (Circle)shapes[0];
  15. c.draw();
  16. c.move(10, 10.1);
  17. }
  18.  
  19. private abstract class Shape {
  20. private double x = 0, y = 0;
  21. public Shape(double x, double y) {
  22. this.x = x;
  23. this.y = y;
  24. }
  25. public double getX() { return x; }
  26. public double getY() { return y; }
  27. public abstract void draw();
  28. }
  29. private interface Moveable {
  30. public void move(double x, double y);
  31. }
  32.  
  33. private class Circle extends Shape implements Moveable {
  34. private static final int END = 10;
  35. private int start = 0;
  36. private double radius = 0;
  37. public Circle(double x, double y, double radius) {
  38. super(x, y);
  39. this.radius = 0;
  40. }
  41. public void draw() {
  42. log("draw circle");
  43. log(String.format("center(%.1f, %.1f) - radius(%.1f)", getX(), getY(), radius));
  44. }
  45. public void move(double dx, double dy) {
  46. for (int i=0; i<END; i++) {
  47. log((i+1) + "");
  48. log(String.format("center(%.1f, %.1f) - radius(%.1f)", getX()+dx, getY()+dy, radius));
  49. }
  50. }
  51. }
  52. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
draw circle 
center(100.0, 100.0) - radius(0.0) 
1 
center(110.0, 110.1) - radius(0.0) 
2 
center(110.0, 110.1) - radius(0.0) 
3 
center(110.0, 110.1) - radius(0.0) 
4 
center(110.0, 110.1) - radius(0.0) 
5 
center(110.0, 110.1) - radius(0.0) 
6 
center(110.0, 110.1) - radius(0.0) 
7 
center(110.0, 110.1) - radius(0.0) 
8 
center(110.0, 110.1) - radius(0.0) 
9 
center(110.0, 110.1) - radius(0.0) 
10 
center(110.0, 110.1) - radius(0.0)