I have the following classes:
Point
public class Point {
public Integer x;
public Integer y;
public Point(Integer x, Integer y) {
this.x = x;
this.y = y;
}
PointSet
public class PointSet {
private Point[] arr;
private int index = 0;
public PointSet(int capacity) {
arr = new Point[capacity];
}
public PointSet() {
this(10);
}
In the PointSet
class, I need to implement a method which can add a Point to the internal array and if there is no more room the array size should be doubled and still keeping its original elements.
How can I implement a method which returns a new array with double size and the elements of the internal array?
I am stuck because the default constructor takes 10 as a default value and I can't find a way to double it. I also have to use arrays, so using a list or set won't be an option. Thanks.