Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oo.hide;
- public class PointSet {
- private Point[] points;
- private int arraySize = 10;
- private int currentSize;
- public PointSet(int capacity) {
- points = new Point[capacity];
- currentSize = capacity;
- }
- public PointSet() {
- this(10);
- }
- public void add(Point point) {
- if(currentSize < arraySize) //если есть места в массиве, можно добавить Point
- {
- points[currentSize + 1] = point;
- currentSize = currentSize + 1;
- }
- //иначе нужно создать массив побольше, затем переписать туда все,
- //что уже есть, и только потом добавить новый Point
- else
- {
- Point[] oldPoints = points;
- arraySize = arraySize + currentSize;
- points = new Point[arraySize];
- for(int i=0; i < currentSize ; i++)
- {
- points[i] = oldPoints[i];
- }
- currentSize = currentSize + 1;
- points[currentSize] = point;
- }
- }
- public int size() {
- return points.length;
- }
- public String toString() {
- String hell = "";
- for (int i = 0; i < points.length; i++) {
- if (i == 0) {
- hell += points[i].toString();
- } else {
- hell += (", " + points[i].toString());
- }
- }
- return hell;
- }
- public boolean contains(Point point) {
- for (Point value : points) {
- if (value == point) return true;
- }
- return false;
- }
- public PointSet subtract(PointSet other) {
- return null;
- }
- public PointSet intersect(PointSet other) {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement