Write a simulator that allows the user to move and resize a java.awt.Rectangle object. To move a rectangle object, you can use its setLocation method; and to resize it, simply use the setSize method. You may hardcode a set of actions that the user might do with the simulator. Please see the attached Simulator.java to get an idea. After every action, the simulator should print the description of the action and the state of the rectangle object, for example:

--Move the rectangle to (5, 10): java.awt.Rectangle[x=5,y=10,width=0,height=0]

This simulator must support multi-level undo operations. That is, the simulator must keep track of every undoable action (i.e., move and resize) so that it will be able to undo these actions properly (see the example below). Use the Command Pattern and the Command interface to implement the required features above:

// You must use this interface to implement the Command Pattern
// Do not change this interface.
public interface Command {
public void execute();
public void undo();

Note: A real application might draw rectangles on a panel and allow the user to click-and-drag a rectangle to move it or change its size, but the approach to solving this problem is essentially the same.

Example of a simulation:

--Create a default rectangle1: java.awt.Rectangle[x=0,y=0,width=0,height=0]
--Create a default rectangle2: java.awt.Rectangle[x=0,y=0,width=0,height=0]
--Move rectangle1 to (5, 10): java.awt.Rectangle[x=5,y=10,width=0,height=0]
--Undo, rectangle1 back to: java.awt.Rectangle[x=0,y=0,width=0,height=0]
--Resize rectangle1 to 5 by 10: java.awt.Rectangle[x=0,y=0,width=5,height=10]
--Resize rectangle2 to 8 by 12: java.awt.Rectangle[x=0,y=0,width=8,height=12]
--Move rectangle2 to (10, 20): java.awt.Rectangle[x=10,y=20,width=8,height=12]
--Undo, rectangle2 back to: java.awt.Rectangle[x=0,y=0,width=8,height=12]
--Undo, rectangle2 back to: java.awt.Rectangle[x=0,y=0,width=0,height=0]
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.