Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. class SetCord
  4. {
  5.     public int x;
  6.     public int y;
  7.     private  int Id;
  8.     private static int nextId = 1;
  9.     public SetCord(int a, int b)
  10.     {
  11.         x=a;
  12.         y=b;
  13.     }
  14.     public int getX()
  15.     {
  16.        
  17.         Id=nextId;
  18.         nextId++;
  19.         return x;
  20.     }
  21.     public int getY()
  22.     {
  23.        
  24.         Id=nextId;
  25.         nextId++;
  26.         return y;
  27.     }
  28.  
  29.     public int getId()
  30.     {
  31.         return Id;
  32.     }
  33. }
  34.    class Test{
  35.     public static void main(String args[])
  36.     {
  37.     Random rand = new Random();
  38.     SetCord[] teste = new SetCord[3];
  39.    
  40.     for (int i = 0; i < 3; i++)
  41.     {
  42.         teste[i] = new SetCord(rand.nextInt(100), rand.nextInt(35));
  43.        
  44.     }
  45.    
  46.     for(SetCord x:teste)
  47.     {
  48.    
  49.     System.out.println("x = " +  x.getX());
  50.     System.out.println("y = " +  y.getY());        //blad kompilacj - y cannot be resolved
  51.     System.out.println("x id " +  x.getId());
  52.     System.out.println("y id " +  y.getId());  //blad kompilacj - y cannot be resolved
  53.        
  54.    }  
  55.  
  56.     }
  57.    
  58.    
  59.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement