Advertisement
UniQuet0p1

Untitled

Feb 23rd, 2022
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package oo.hide;
  2.  
  3. public class PointSet {
  4.  
  5.     private Point[] points;
  6.     private int arraySize = 10;
  7.     private  int currentSize;
  8.  
  9.  
  10.  
  11.  
  12.     public PointSet(int capacity) {
  13.         points = new Point[capacity];
  14.         currentSize = capacity;
  15.     }
  16.     public PointSet() {
  17.         this(10);
  18.     }
  19.  
  20.  
  21.     public void add(Point point) {
  22.         if(currentSize < arraySize) //если есть места в массиве, можно добавить Point
  23.         {
  24.             points[currentSize + 1] = point;
  25.             currentSize = currentSize + 1;
  26.         }
  27. //иначе нужно создать массив побольше, затем переписать туда все,
  28. //что уже есть, и только потом добавить новый Point
  29.         else
  30.         {
  31.             Point[] oldPoints = points;
  32.             arraySize = arraySize + currentSize;
  33.             points = new Point[arraySize];
  34.             for(int i=0; i < currentSize ; i++)
  35.             {
  36.                 points[i] = oldPoints[i];
  37.             }
  38.             currentSize = currentSize + 1;
  39.             points[currentSize] = point;
  40.         }
  41.     }
  42.  
  43.  
  44.     public int size() {
  45.         return points.length;
  46.     }
  47.  
  48.     public String toString() {
  49.         String hell = "";
  50.         for (int i = 0; i < points.length; i++) {
  51.             if (i == 0) {
  52.                 hell += points[i].toString();
  53.             } else {
  54.                 hell += (", " + points[i].toString());
  55.             }
  56.         }
  57.         return hell;
  58.     }
  59.  
  60.     public boolean contains(Point point) {
  61.         for (Point value : points) {
  62.             if (value == point) return true;
  63.         }
  64.         return  false;
  65.     }
  66.  
  67.     public PointSet subtract(PointSet other) {
  68.         return null;
  69.     }
  70.  
  71.     public PointSet intersect(PointSet other) {
  72.         return null;
  73.     }
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement