Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. package oo.hide;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class PointSet {
  6.  
  7. private Point[] set;
  8.  
  9. public PointSet(int capacity) {
  10. set = new Point[capacity];
  11. }
  12.  
  13. public PointSet() {
  14. this(10);
  15. }
  16.  
  17. public void add(Point point) {
  18. for(int i = 0; i < set.length; i++) {
  19. if(point.equals(set[i])) {
  20. break;
  21. } else if (set[i] == null){
  22. set[i] = point;
  23. break;
  24. }
  25. }
  26. }
  27.  
  28. public int size() {
  29. int count = 0;
  30. for (Point point : set) {
  31. if (point != null) {
  32. count += 1;
  33. }
  34. }
  35. return count;
  36. }
  37.  
  38. public boolean contains(Point point) {
  39. boolean isInSet = false;
  40. for (Point value : set) {
  41. if (point.equals(value)) {
  42. isInSet = true;
  43. break;
  44. }
  45. }
  46. return isInSet;
  47. }
  48.  
  49. public String toString() {
  50. int size = size();
  51. Point[] array = Arrays.copyOfRange(set, 0, size);
  52.  
  53. return Arrays.toString(array).replace("[", "").replace("]", "").trim();
  54. }
  55.  
  56. public boolean equals(Point point) {
  57. return false;
  58.  
  59. }
  60.  
  61. public PointSet subtract(PointSet other) {
  62. return null;
  63. }
  64.  
  65. public PointSet intersect(PointSet other) {
  66. return null;
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement