Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package kursovrchernyak;
  6.  
  7. /**
  8.  *
  9.  * @author paul
  10.  */
  11. import java.util.Random;
  12.  
  13. class MyPoint {
  14.         int x, y;
  15.         static Random random = new Random();
  16.  
  17.         MyPoint(int xx, int yy) { // Constractor
  18.                 x=xx;
  19.                 y=yy;
  20.         }
  21.  
  22.         public MyPoint() { // Constractor
  23.                 this(random.nextInt(), random.nextInt());
  24.         }
  25.  
  26.         public int getX() {return x;}
  27.         public int getY() {return y;}
  28.  
  29.         public boolean isEqual(MyPoint p) {
  30.                 return this.getX() == p.getX() && this.getY() == p.getY();
  31.         }
  32.  
  33.         /** Create array of random points. */
  34.         public static MyPoint[] newArray(int len) {
  35.                 MyPoint[] arr = new MyPoint[len];
  36.                 for(int i=0; i < arr.length; i++) {
  37.                         arr[i] = new MyPoint();
  38.                 }
  39.                 return arr;
  40.         }
  41.         /** Create array of random points (x=y) sorted  by x */
  42.         public static MyPoint[] newSortedArray(int len) {
  43.  
  44.                 MyPoint[] arr = new MyPoint[len];
  45.                 for(int i=0, a=0; i < arr.length; i++) {
  46.                         a += random.nextInt();
  47.                         arr[i] = new MyPoint(a,a);
  48.                 }
  49.                 return arr;
  50.         }
  51.  
  52.        
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement