Advertisement
trongdatvu

Bai2

Aug 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. interface In {
  5. public void print();
  6. }
  7.  
  8. class Point {
  9. private double x;
  10. private double y;
  11.  
  12. public Point() {
  13. this.x = 0.0;
  14. this.y = 0.0;
  15. }
  16.  
  17. public Point(double x, double y) {
  18. this.x = x;
  19. this.y = y;
  20. }
  21. }
  22.  
  23. abstract class Shape implements In {
  24. private enum Painter {
  25. BRUSH,
  26. BALLPEN
  27. }
  28. private enum Color {
  29. RED,
  30. GREEN,
  31. BLUE
  32. }
  33. }
  34.  
  35. class Line extends Shape {
  36. private Point startP;
  37. private Point endP;
  38.  
  39. public Line() {
  40. this.startP = new Point();
  41. this.endP = new Point();
  42. }
  43.  
  44. public Line(Point startP, Point endP) {
  45. this.startP = startP;
  46. this.endP = endP;
  47. }
  48.  
  49. @Override
  50. public void print() {
  51. System.out.println("Line");
  52. }
  53. }
  54.  
  55. class Circle extends Shape {
  56. private Point tam;
  57. private double R;
  58.  
  59. public Circle() {
  60. this.tam = new Point();
  61. this.R = 0.0;
  62. }
  63.  
  64. public Circle(Point tam, double R) {
  65. this.tam = tam;
  66. this.R = R;
  67. }
  68.  
  69. @Override
  70. public void print() {
  71. System.out.println("Circle");
  72. }
  73. }
  74.  
  75. class Rectangle extends Shape {
  76. private Point diemTrenTrai;
  77. private Point diemDuoiPhai;
  78.  
  79. public Rectangle() {
  80. this.diemTrenTrai = new Point();
  81. this.diemDuoiPhai = new Point();
  82. }
  83.  
  84. public Rectangle(Point diemTrenTrai, Point diemDuoiPhai) {
  85. this.diemTrenTrai = diemTrenTrai;
  86. this.diemDuoiPhai = diemDuoiPhai;
  87. }
  88.  
  89. @Override
  90. public void print() {
  91. System.out.println("Rectangle");
  92. }
  93.  
  94. @Override
  95. public boolean equals(Object o) {
  96. if (o instanceof Rectangle) {
  97. return this == o && this.diemTrenTrai.equals(((Rectangle) o).diemTrenTrai)
  98. && this.diemDuoiPhai.equals(((Rectangle) o).diemDuoiPhai);
  99. } else {
  100. return false;
  101. }
  102. }
  103. }
  104.  
  105. class Image implements In {
  106. private Line line;
  107. private Circle circle;
  108. private Rectangle rectangle;
  109.  
  110. public Image() {
  111. this.line = new Line();
  112. this.circle = new Circle();
  113. this.rectangle = new Rectangle();
  114. }
  115.  
  116. public Image(Line _line, Circle _circle, Rectangle _rectangle) {
  117. this.line = _line;
  118. this.circle = _circle;
  119. this.rectangle = _rectangle;
  120. }
  121.  
  122. @Override
  123. public void print() {
  124. line.print();
  125. circle.print();
  126. rectangle.print();
  127. }
  128. }
  129.  
  130. class Main {
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement