fork(1) download
  1. import java.util.Scanner;
  2.  
  3. abstract class Figure {
  4. protected int x;
  5. protected int y;
  6. public static int count;
  7. public static int getCount(){
  8. return count;
  9. }
  10.  
  11. public int getX() {
  12. return x;
  13. }
  14.  
  15. public int getY() {
  16. return y;
  17. }
  18.  
  19. public void setX(int x) {
  20. this.x = x;
  21. }
  22.  
  23. public void setY(int y) {
  24. this.y = y;
  25. }
  26.  
  27. abstract void draw();
  28.  
  29. abstract void move();
  30. }
  31.  
  32. class Line extends Figure {
  33. int x2;
  34. int y2;
  35.  
  36.  
  37. Line(int k1, int l1, int k2, int l2) {
  38. count++;
  39. super.x = k1;
  40. super.y = l1;
  41. x2 = k2;
  42. y2 = l2;
  43.  
  44.  
  45. }
  46.  
  47. void draw() {
  48. System.out.println("Линия");
  49. System.out.println("Координаты:");
  50. System.out.println("(x1;y1):" + "(" + x + ";" + y + ")");
  51. System.out.println("(x2;y2):" + "(" + x2 + ";" + y2 + ")");
  52. }
  53.  
  54. void move() {
  55. Scanner scanner = new Scanner(System.in);
  56. System.out.println("Сдвинуть фигуру");
  57. System.out.print("По оси X: ");
  58. int t = scanner.nextInt();
  59. System.out.print("По оси Y: ");
  60. int t2 = scanner.nextInt();
  61. x = x + t;
  62. x2 = x2 + t;
  63. y = y + t2;
  64. y2 = y2 + t2;
  65. System.out.println("Новые координаты фигуры: ");
  66. System.out.println("(x1;y1):" + "(" + x + ";" + y + ")");
  67. System.out.println("(x2;y2):" + "(" + x2 + ";" + y2 + ")");
  68. }
  69. }
  70. class Rectangle extends Figure {
  71.  
  72. int x2;
  73. int y2;
  74. int x3;
  75. int y3;
  76. int x4;
  77. int y4;
  78.  
  79. Rectangle(int k1, int l1, int l2, int k3) {
  80. count++;
  81. super.x = k1;
  82. super.y = l1;
  83. x2 = x;
  84. y2 = l2;
  85. x3 = k3;
  86. y3 = y;
  87. x4 = x3;
  88. y4 = y2;
  89. }
  90.  
  91. void draw() {
  92.  
  93. System.out.println("Прямоугольник");
  94. System.out.println("Координаты:");
  95. System.out.println("(x1;y1):" + "(" + x + ";" + y + ")");
  96. System.out.println("(x2;y2):" + "(" + x2 + ";" + y2 + ")");
  97. System.out.println("(x3;y3):" + "(" + x3 + ";" + y3 + ")");
  98. System.out.println("(x4;y4):" + "(" + x4 + ";" + y4 + ")");
  99. }
  100.  
  101. void move() {
  102. Scanner scanner = new Scanner(System.in);
  103. System.out.println("Сдвинуть фигуру");
  104. System.out.print("По оси X: ");
  105. int t = scanner.nextInt();
  106. System.out.print("По оси Y: ");
  107. int t2 = scanner.nextInt();
  108. x = x + t;
  109. x2 = x2 + t;
  110. x3 = x3 + t;
  111. x4 = x4 + t;
  112. y = y + t2;
  113. y2 = y2 + t2;
  114. y3 = y3 + t2;
  115. y4 = y4 + t2;
  116. System.out.println("Новые координаты фигуры: ");
  117. System.out.println("(x1;y1):" + "(" + x + ";" + y + ")");
  118. System.out.println("(x2;y2):" + "(" + x2 + ";" + y2 + ")");
  119. System.out.println("(x3;y3):" + "(" + x3 + ";" + y3 + ")");
  120. System.out.println("(x4;y4):" + "(" + x4 + ";" + y4 + ")");
  121. }
  122. }
  123. class Circle extends Figure {
  124. int r;
  125.  
  126. Circle(int k1, int l1, int u) {
  127. count++;
  128. super.x = k1;
  129. super.y = l1;
  130. r = u;
  131. }
  132.  
  133. void draw() {
  134.  
  135. System.out.println("Круг");
  136. System.out.println("Координаты:");
  137. System.out.println("Центр (x;y):" + "(" + x + ";" + y + ")");
  138. System.out.println("Верхняя точка: " + "(" + x + ";" + (y + r) + ")");
  139. System.out.println("Левая точка: " + "(" + (x - r) + ";" + y + ")");
  140. System.out.println("Нижняя точка: " + "(" + x + ";" + (y - r) + ")");
  141. System.out.println("Правая точка: " + "(" + (x + r) + ";" + y + ")");
  142. }
  143.  
  144. void move() {
  145. Scanner scanner = new Scanner(System.in);
  146. System.out.println("Сдвинуть фигуру");
  147. System.out.print("По оси X: ");
  148. int t = scanner.nextInt();
  149. System.out.print("По оси Y: ");
  150. int t2 = scanner.nextInt();
  151. x = x + t;
  152. y = y + t2;
  153. System.out.println("Новые координаты фигуры: ");
  154. System.out.println("Центр (x;y):" + "(" + x + ";" + y + ")");
  155. System.out.println("Верхняя точка: " + "(" + x + ";" + (y + r) + ")");
  156. System.out.println("Левая точка: " + "(" + (x - r) + ";" + y + ")");
  157. System.out.println("Нижняя точка: " + "(" + x + ";" + (y - r) + ")");
  158. System.out.println("Правая точка: " + "(" + (x + r) + ";" + y + ")");
  159. }
  160. }
  161. class CompositeFigure extends Figure {
  162.  
  163. CompositeFigure() {
  164.  
  165. Figure[] figures = new Figure[3];
  166. figures[0] = new Line(1, 1, 5, 5);
  167. figures[1] = new Rectangle(1, 1, 4, 5);
  168. figures[2] = new Circle(1, 4, 5);
  169. }
  170.  
  171.  
  172.  
  173. void draw() {
  174. }
  175.  
  176. void move() {
  177. }
  178. }
  179.  
  180. class Activity {
  181. public static void main(String[] args) {
  182. Line line = new Line(1, 1, 4, 2);
  183. Circle circle = new Circle(0, 0, 2);
  184. Rectangle rectangle = new Rectangle(3, 3, 4, 6);
  185. Figure[] figures = new Figure[3];
  186.  
  187. line.draw();
  188. line.move();
  189.  
  190. rectangle.draw();
  191. rectangle.move();
  192.  
  193. circle.draw();
  194. circle.move();
  195.  
  196. for(int n = 0; n < 3; n++)
  197. figures[n].draw();
  198.  
  199. //System.out.print(GetCount);
  200. }
  201. }
  202.  
Runtime error #stdin #stdout #stderr 0.11s 381696KB
stdin
Standard input is empty
stdout
Линия
Координаты:
(x1;y1):(1;1)
(x2;y2):(4;2)
Сдвинуть фигуру
По оси X: 
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:907)
	at java.util.Scanner.next(Scanner.java:1530)
	at java.util.Scanner.nextInt(Scanner.java:2160)
	at java.util.Scanner.nextInt(Scanner.java:2119)
	at Line.move(Main.java:58)
	at Activity.main(Main.java:188)