Advertisement
Guest User

Untitled

a guest
Mar 26th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. package two;
  2. import java.util.Scanner;
  3.  
  4. public class zadacha_02 {
  5.  
  6. public static void main(String[] args) {
  7. Scanner input=new Scanner(System.in);
  8. ColorRectangle rect=new ColorRectangle();
  9. ColorRectangle rect1=new ColorRectangle();
  10. System.out.println(rect.toString());
  11. System.out.println(rect1.toString());
  12. System.out.println("Enter number to translate X and Y: ");
  13. rect.translateXY(input.nextInt());
  14. System.out.println(rect.toString());
  15. System.out.println(rect.equals(rect1));
  16. System.out.println(rect.intersectionRect(rect1));
  17. System.out.println(rect.intersectionRect(rect1).Area());
  18. System.out.println(rect.unionRect(rect1));
  19. System.out.println(rect.unionRect(rect1).Area());
  20. System.out.println("Insert two values for X and Y: ");
  21. System.out.println(rect.isInside(input.nextInt(), input.nextInt()));
  22. Color color=new Color();
  23. System.out.println("Value of R is: "+color.getRValue());
  24. System.out.println("Value of G is: "+color.getGValue());
  25. System.out.println("Value of B is: "+color.getBValue());
  26.  
  27. }
  28.  
  29. }
  30. class Console
  31. {
  32. static String a, b;
  33. public static Long readLine()
  34. {
  35. Scanner input=new Scanner(System.in);
  36. a=input.next();
  37. long a1=Long.parseLong(a);
  38. return a1;
  39. }
  40. public static int readLineInt()
  41. {
  42. Scanner input=new Scanner(System.in);
  43. b=input.next();
  44. int b1=Integer.parseInt(b);
  45. return b1;
  46. }
  47.  
  48. }
  49. class Color implements Comparable<Color>
  50. {
  51. private long RValue, GValue, BValue, RGBValue;
  52. Color()
  53. {
  54. System.out.println("Insert Value of R:");
  55. RValue=Console.readLine();
  56. System.out.println("Insert Value of G:");
  57. GValue=Console.readLine();
  58. System.out.println("Insert Value of B:");
  59. BValue=Console.readLine();
  60. }
  61. public void setRValue(long RValue)
  62. {
  63. this.RValue=RValue;
  64. }
  65. public long getRValue()
  66. {
  67. return RValue;
  68. }
  69. public void setGValue(long GValue)
  70. {
  71. this.GValue=GValue;
  72. }
  73. public long getGValue()
  74. {
  75. return GValue;
  76. }
  77. public void setBValue(long BValue)
  78. {
  79. this.BValue=BValue;
  80. }
  81. public long getBValue()
  82. {
  83. return BValue;
  84. }
  85. public long getRGBValue()
  86. {
  87. return this.RGBValue=256*256*getRValue()+256*getGValue()+1*getBValue();
  88. }
  89. public String toString()
  90. {
  91. return ("Value of Red is: "+this.RValue+" "+"Value of Green is: "+this.GValue+" "+"Value of Blue is: "+this.BValue+" "+"Value of Total is: "+getRGBValue());
  92. }
  93. public boolean equals(long r)
  94. {
  95. if (this.RGBValue==r)
  96. return true;
  97. else
  98. return false;
  99. }
  100. @Override
  101. public int compareTo(Color arg0) {
  102. if (this.RGBValue<arg0.RGBValue) {
  103. return -1;
  104. }
  105. if (this.RGBValue==arg0.RGBValue) {
  106. return 0;
  107. }
  108. return 1;
  109. }
  110. }
  111. class ColorRectangle
  112. {
  113. private int iX1, iY1, iX2, iY2;
  114. ColorRectangle()
  115. {
  116. System.out.println("Insert Value of iX1:");
  117. iX1=Console.readLineInt();
  118. System.out.println("Insert Value of iX2:");
  119. iX2=Console.readLineInt();
  120. System.out.println("Insert Value of iY1:");
  121. iY1=Console.readLineInt();
  122. System.out.println("Insert Value of iY2:");
  123. iY2=Console.readLineInt();
  124. }
  125. public ColorRectangle(int x1, int y1, int x2, int y2)
  126. {
  127. this.iX1=x1;
  128. this.iY1=y1;
  129. this.iX2=x2;
  130. this.iY2=y2;
  131. }
  132. public int getIX1()
  133. {
  134. return iX1;
  135. }
  136. public int getIY1()
  137. {
  138. return iY1;
  139. }
  140. public int getIX2()
  141. {
  142. return iX2;
  143. }
  144. public int getIY2()
  145. {
  146. return iY2;
  147. }
  148. public void setIX1(int x1)
  149. {
  150. this.iX1=x1;
  151. }
  152. public void setIX2(int x2)
  153. {
  154. this.iX2=x2;
  155. }
  156. public void setIY1(int y1)
  157. {
  158. this.iY1=y1;
  159. }
  160. public void setIY2(int y2)
  161. {
  162. this.iY2=y2;
  163. }
  164. public String toString()
  165. {
  166. return ("X1:"+this.iX1+" X2:"+this.iX2+" Y1:"+this.iY1+" Y2:"+this.iY2);
  167. }
  168. public int Area()
  169. {
  170. return (iX2-iX1)*(iY2-iY1);
  171. }
  172. public boolean equals(ColorRectangle r)
  173. {
  174. if(this.iX1==r.iX1 && this.iX2==r.iX2 && this.iY1==r.iY1 && this.iY2==r.iY2)
  175. return true;
  176. else
  177. return false;
  178. }
  179. public void translateX(int iPoints)
  180. {
  181. this.iX1+=iPoints;
  182. this.iX2+=iPoints;
  183. }
  184. public void translateY(int iPoints)
  185. {
  186. this.iY1+=iPoints;
  187. this.iY2+=iPoints;
  188. }
  189. public void translateXY(int iPoints)
  190. {
  191. this.iX1+=iPoints;
  192. this.iX2+=iPoints;
  193. this.iY1+=iPoints;
  194. this.iY2+=iPoints;
  195. }
  196. public boolean isInside(int ptX, int ptY )
  197. {
  198. if((ptX>=this.iX1 && ptX<=this.iX2) && (ptY>=this.iY1 && ptY<=this.iY2))
  199. return true;
  200. else
  201. return false;
  202. }
  203. public int compareTo(ColorRectangle r)
  204. {
  205. if(this.Area()-r.Area()<0)
  206. return -1;
  207. if(this.Area()-r.Area()==0)
  208. return 0;
  209. return 1;
  210. }
  211. public ColorRectangle unionRect(ColorRectangle r)
  212. {
  213. return new ColorRectangle((this.iX1<r.iX1) ? this.iX1:r.iX1, (this.iY1<r.iY1) ? this.iY1:r.iY1, (this.iX2>r.iX2) ? this.iX2:r.iX2, (this.iY2>r.iY2) ? this.iY2:r.iY2);
  214. }
  215. public ColorRectangle intersectionRect(ColorRectangle r)
  216. {
  217. ColorRectangle result = new ColorRectangle((this.iX1>r.iX1) ? this.iX1:r.iX1, (this.iY1>r.iY1) ? this.iY1:r.iY1, (this.iX2<r.iX2) ? this.iX2:r.iX2, (this.iY2<r.iY2) ? this.iY2:r.iY2);
  218. if (result.iX1>result.iX2) { result.iX1 = result.iX2 = 0; }
  219. if (result.iY1>result.iY2) { result.iY1 = result.iY2 = 0; }
  220. return result;
  221. }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement