Starting from:

$25

OOAD - Assignment 2 - PART 2 - Solved


In Lecture 10 we saw a demo of a Graphical User Interface (GUI) for trees and duptrees.   A screen-shot of the GUI is shown below.  Using this GUI we can perform the four familiar operations on trees and duptrees: insert, delete, min, and max.     

 

  

 

Most of the code for Part 2 is given at Resources → Assignments → TreeGUI.java.   The focus of Part 2 is on the Undo operation using which you should be able to undo all changes made to the tree/duptree, restoring earlier trees/duptrees.    You are to code the following pieces:  

 

(i)      The clone() operation in class AbsTree;

(ii)    The entire class TreeMemento;

(iii)  The actionPerformed method for UndoButton in TreeGUI();

 

The definition of the actionPerformed method for UndoButton is similar to those for insertButton and deleteButton (given in the file).   You may need to add some extra fields in class TreeGUI as well as some extra code for the other buttons (clearButton, insertButton, and deleteButton) in order to support the Undo operation.  Test your program by interleaving insert’s, delete’s, and undo’s.

 

Note: The insert and delete methods here differ from those of A1 Part 1 in that they return a boolean indicating whether the state of the tree/duptree has changed.   The code for the deleteButton should recognize when a tree/duptree will become empty and should take suitable actions.

 

Exceptions to be raised: “No more undo operations are possible,” “Cannot delete from an empty tree,” “Cannot delete non-existent value n”, “Number format error – please re-enter value.” 

 



 

End of Assignment 2 Part 2 

More products