fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Point
  8. {
  9. public int X;
  10. public int Y;
  11. }
  12.  
  13. class PointArray
  14. {
  15. private Point[] array;
  16. public PointArray(int size) throws Exception
  17. {
  18. if(size <= 0) throw new Exception("Array size less equal zero.");
  19. this.array = new Point[size];
  20. }
  21.  
  22. public void SetCoordinates(int index, int x, int y) throws Exception
  23. {
  24. if(index < this.array.length && index > 0)
  25. {
  26. this.array[index].X = x;
  27. this.array[index].Y = y;
  28. }
  29. else throw new Exception("Array index out or range.");
  30. }
  31.  
  32. public Point GetCoordinates(int index) throws Exception
  33. {
  34. if(index < this.array.length && index > 0)
  35. {
  36. return this.array[index];
  37. }
  38. else throw new Exception("Array index out or range.");
  39. }
  40. }
  41.  
  42. class Ideone
  43. {
  44. public static void main (String[] args) throws java.lang.Exception
  45. {
  46. try
  47. {
  48. PointArray pa = new PointArray(1);
  49. pa.SetCoordinates(1,1,1);
  50. Point point = pa.GetCoordinates(2);
  51. }
  52. catch(Exception ex)
  53. {
  54. System.out.println(ex);
  55. }
  56. }
  57. }
Success #stdin #stdout 0.11s 320512KB
stdin
Standard input is empty
stdout
java.lang.Exception: Array index out or range.