Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oo.hide;
- import java.util.Arrays;
- public class PointSet {
- private Point[] set;
- public PointSet(int capacity) {
- set = new Point[capacity];
- }
- public PointSet() {
- this(10);
- }
- public void add(Point point) {
- for(int i = 0; i < set.length; i++) {
- if(point.equals(set[i])) {
- break;
- } else if (set[i] == null){
- set[i] = point;
- break;
- }
- }
- }
- public int size() {
- int count = 0;
- for (Point point : set) {
- if (point != null) {
- count += 1;
- }
- }
- return count;
- }
- public boolean contains(Point point) {
- boolean isInSet = false;
- for (Point value : set) {
- if (point.equals(value)) {
- isInSet = true;
- break;
- }
- }
- return isInSet;
- }
- public String toString() {
- int size = size();
- Point[] array = Arrays.copyOfRange(set, 0, size);
- return Arrays.toString(array).replace("[", "").replace("]", "").trim();
- }
- public boolean equals(Point point) {
- 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