tuxmartin

PGRF2 - test 1

Mar 20th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.32 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2.  
  3. public class PGRF2_test1 {
  4.  
  5.     public static class Point2D {
  6.         public double x, y, w;
  7.  
  8.         public Point2D() {
  9.             x = y = 0.0;
  10.             w = 1.0;
  11.         }
  12.         public Point2D(Point2D v) {
  13.             x = v.x;
  14.             y = v.y;
  15.             w = v.w;
  16.         }
  17.         public Point2D(double x, double y) {
  18.             this.x = x;
  19.             this.y = y;
  20.             w = 1.0;
  21.         }
  22.     }
  23.  
  24.     public static Point2D[][] pole = new Point2D[10][10];
  25.  
  26.     static DecimalFormat df = new DecimalFormat("#.###");
  27.     // formatovani informacniho vypisu
  28.  
  29.     private static void otazka2() {
  30.         for (int i = 0; i < 10; i++) {
  31.             for (int j = 0; j < 10; j++) {
  32.                 pole[i][j] = new Point2D(Math.random(), Math.random());
  33.  
  34.                 /* informacni vypis */
  35.                 System.out.println("pole[" + i + "][" + j + "]: x = "
  36.                         + df.format(pole[i][j].x) + " y = "
  37.                         + df.format(pole[i][j].y));
  38.                 /* informacni vypis */
  39.             }
  40.         }
  41.     }
  42.  
  43.     private static void otazka3() {
  44.         Point2D max = pole[0][0];
  45.         // zatim nezname maximum, takze je prvni prvek pro nas nejevetsi znamy
  46.  
  47.         for (int i = 0; i < 10; i++) {
  48.             for (int j = 0; j < 10; j++) {
  49.                 if (max.x < pole[i][j].x) {
  50.                     max = pole[i][j];
  51.                 }
  52.             }
  53.         }
  54.  
  55.         /* informacni vypis */
  56.         System.out.println("maximum: x = " + df.format(max.x) + " y = "
  57.                 + df.format(max.y));
  58.         /* informacni vypis */
  59.     }
  60.  
  61.     private static void otazka4() {
  62.         Point2D a = new Point2D();
  63.         Point2D b = new Point2D(a);
  64.         Point2D c = new Point2D(-5, 0);
  65.         a = c;
  66.         a.x += 10;
  67.         b.x += 2;
  68.         if (c.x > b.x) {
  69.             a.x++;
  70.         }
  71.         a.y = 3;
  72.         b.y += a.y++;
  73.  
  74.         System.out.println("a.x = " + a.x);
  75.         System.out.println("a.y = " + a.y);
  76.  
  77.         System.out.println("b.x = " + b.x);
  78.         System.out.println("b.y = " + b.y);
  79.  
  80.         System.out.println("c.x = " + c.x);
  81.         System.out.println("c.y = " + c.y);
  82.  
  83.     }
  84.  
  85.     public static void main(String[] args) {
  86.         System.out.println("Otazka 2:");
  87.         otazka2();
  88.  
  89.         System.out.println("\n Otazka 3:");
  90.         otazka3();
  91.  
  92.         System.out.println("\n Otazka 4:");
  93.         otazka4();
  94.     }
  95. }
  96.  
  97. /*
  98. VYSTUP:
  99.  
  100. Otazka 2:
  101. pole[0][0]: x = 0,312 y = 0,686
  102. pole[0][1]: x = 0,659 y = 0,882
  103. pole[0][2]: x = 0,568 y = 0,163
  104. pole[0][3]: x = 0,899 y = 0,362
  105. pole[0][4]: x = 0,042 y = 0,835
  106. pole[0][5]: x = 0,778 y = 0,306
  107. pole[0][6]: x = 0,193 y = 0,885
  108. pole[0][7]: x = 0,618 y = 0,225
  109. pole[0][8]: x = 0,979 y = 0,591
  110. pole[0][9]: x = 0,183 y = 0,101
  111. pole[1][0]: x = 0,615 y = 0,274
  112. pole[1][1]: x = 0,789 y = 0,716
  113. pole[1][2]: x = 0,552 y = 0,581
  114. pole[1][3]: x = 0,194 y = 0,104
  115. pole[1][4]: x = 0,564 y = 0,804
  116. pole[1][5]: x = 0,058 y = 0,913
  117. pole[1][6]: x = 0,655 y = 0,606
  118. pole[1][7]: x = 0,186 y = 0,807
  119. pole[1][8]: x = 0,69 y = 0,882
  120. pole[1][9]: x = 0,019 y = 0,633
  121. pole[2][0]: x = 0,279 y = 0,454
  122. pole[2][1]: x = 0,046 y = 0,729
  123. pole[2][2]: x = 0,443 y = 0,002
  124. pole[2][3]: x = 0,912 y = 0,649
  125. pole[2][4]: x = 0,056 y = 0,874
  126. pole[2][5]: x = 0,989 y = 0,551
  127. pole[2][6]: x = 0,848 y = 0,451
  128. pole[2][7]: x = 0,096 y = 0,714
  129. pole[2][8]: x = 0,013 y = 0,316
  130. pole[2][9]: x = 0,871 y = 0,912
  131. pole[3][0]: x = 0,125 y = 0,783
  132. pole[3][1]: x = 0,025 y = 0,92
  133. pole[3][2]: x = 0,083 y = 0,256
  134. pole[3][3]: x = 0,327 y = 0,011
  135. pole[3][4]: x = 0,298 y = 0,512
  136. pole[3][5]: x = 0,717 y = 0,137
  137. pole[3][6]: x = 0,178 y = 0,191
  138. pole[3][7]: x = 0,379 y = 0,403
  139. pole[3][8]: x = 0,242 y = 0,75
  140. pole[3][9]: x = 0,957 y = 0,582
  141. pole[4][0]: x = 0,877 y = 0,639
  142. pole[4][1]: x = 0,355 y = 0,649
  143. pole[4][2]: x = 0,832 y = 0,711
  144. pole[4][3]: x = 0,716 y = 0,764
  145. pole[4][4]: x = 0,022 y = 0,721
  146. pole[4][5]: x = 0,247 y = 0,688
  147. pole[4][6]: x = 0,129 y = 0,328
  148. pole[4][7]: x = 0,533 y = 0,337
  149. pole[4][8]: x = 0,777 y = 0,164
  150. pole[4][9]: x = 0,858 y = 0,11
  151. pole[5][0]: x = 0,763 y = 0,412
  152. pole[5][1]: x = 0,838 y = 0,621
  153. pole[5][2]: x = 0,955 y = 0,798
  154. pole[5][3]: x = 0,367 y = 0,692
  155. pole[5][4]: x = 0,964 y = 0,074
  156. pole[5][5]: x = 0,468 y = 0,825
  157. pole[5][6]: x = 0,658 y = 0,886
  158. pole[5][7]: x = 0,161 y = 0,862
  159. pole[5][8]: x = 0,885 y = 0,357
  160. pole[5][9]: x = 0,847 y = 0,227
  161. pole[6][0]: x = 0,53 y = 0,871
  162. pole[6][1]: x = 0,053 y = 0,977
  163. pole[6][2]: x = 0,176 y = 0,299
  164. pole[6][3]: x = 0,583 y = 0,834
  165. pole[6][4]: x = 0,181 y = 0,358
  166. pole[6][5]: x = 0,256 y = 0,564
  167. pole[6][6]: x = 0,955 y = 0,867
  168. pole[6][7]: x = 0,465 y = 0,3
  169. pole[6][8]: x = 0,571 y = 0,432
  170. pole[6][9]: x = 0,707 y = 0,916
  171. pole[7][0]: x = 0,624 y = 0,483
  172. pole[7][1]: x = 0,095 y = 0,113
  173. pole[7][2]: x = 0,423 y = 0,635
  174. pole[7][3]: x = 0,63 y = 0,684
  175. pole[7][4]: x = 0,193 y = 0,097
  176. pole[7][5]: x = 0,647 y = 0,317
  177. pole[7][6]: x = 0,941 y = 0,175
  178. pole[7][7]: x = 0,433 y = 0,37
  179. pole[7][8]: x = 0,042 y = 0,997
  180. pole[7][9]: x = 0,493 y = 0,308
  181. pole[8][0]: x = 0,409 y = 0,217
  182. pole[8][1]: x = 0,302 y = 0,85
  183. pole[8][2]: x = 0,3 y = 0,846
  184. pole[8][3]: x = 0,68 y = 0,441
  185. pole[8][4]: x = 0,455 y = 0,327
  186. pole[8][5]: x = 0,122 y = 0,341
  187. pole[8][6]: x = 0,257 y = 0,619
  188. pole[8][7]: x = 0,498 y = 0,507
  189. pole[8][8]: x = 0,036 y = 0,4
  190. pole[8][9]: x = 0,566 y = 0,436
  191. pole[9][0]: x = 0,498 y = 0,416
  192. pole[9][1]: x = 0,626 y = 0,311
  193. pole[9][2]: x = 0,446 y = 0,663
  194. pole[9][3]: x = 0,483 y = 0,119
  195. pole[9][4]: x = 0,673 y = 0,357
  196. pole[9][5]: x = 0,599 y = 0,899
  197. pole[9][6]: x = 0,895 y = 0,57
  198. pole[9][7]: x = 0,94 y = 0,893
  199. pole[9][8]: x = 0,088 y = 0,012
  200. pole[9][9]: x = 0,58 y = 0,193
  201.  
  202.  Otazka 3:
  203. maximum: x = 0,989 y = 0,551
  204.  
  205.  Otazka 4:
  206. a.x = 6.0
  207. a.y = 4.0
  208. b.x = 2.0
  209. b.y = 3.0
  210. c.x = 6.0
  211. c.y = 4.0
  212.  
  213. */
Advertisement
Add Comment
Please, Sign In to add comment