I have a custom Rectangle class:
public class Rectangle () {
private int height, width, x, y;
private Color color;
public Rectangle () {
this.height = null;
this.width = null;
this.x = null;
this.y = null;
this.color = null;
}
public void setHeight(int h) { this.height = h; }
public void setWidth(int w) { this.width = w; }
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
public void setColor(Color c) { this.color = c; }
public int getWidth() { return this.width; }
public int getHeight() { return this.height; }
public int getX() { return this.x; }
public int getY() { return this.y; }
public Color getColor() { return this.color; }
public void undo() { }
public void redo() { }
}
How would I go about implementing the undo and redo functions for this class in a way that it should be able to revert the rectangle to its previous state without the user mentioning what method was last used. I have a vague idea that involves using a stack but I'm stuck on how to actually code it. My second question is I'm not sure if my constructor is correct, I initialize everything to null without giving any parameters because I want people to use the getters/setters instead. Please help.