Instructions
Practice Problems
Problem 1
Problem 2
Version: 5.2.1

Assignment 8

Goals: Practice working with ArrayList and Comparator. Learn to define and use visitors to provide extensibility for a union of classes.

Instructions

The names of the projects and some of the project files must be exactly the same as specified in the assignment. Failure to do so makes it impossible for the graders to run your submission and results in immediate loss of at least 50% of the homework credit.

Make sure you follow the style guidelines for code indentation.

You will submit this assignment by the deadline using the Web-CAT submission system.

With each homework you will also submit your log file named pairxxx.txt where you replace xxx with your pair number.

On top of every file you submit you will have the names of both partners, and the pair number.

The .txt file will be the log of your work on this assignment. Each log entry will have data and time, who was present (one or both of the partners) and a short comment decribing what you were working on.

Due Date: Monday, November 5th, 11:59 pm.

Practice Problems

Work out these problems on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Problem 1

Problem 2

You will work with a binary search tree that represents a collection of Book objects. (Use the same Book class you have defined for the first problem.)

A binary search tree (BST) is defined by the following class diagram:

                 +------------------------+

                 | abstract class ABST    |

                 +------------------------+

      +----------| Comparator<Book> order |

      |          +------------------------+

      |                 / \

      |                 ---

      |                  |

      |      -----------------

      |      |               |

      |   +------+   +------------+

      |   | Leaf |   | Node       |

      |   +------+   +------------+

      |              | Book data  |--------+

      |              | ABST left  |        |

      |              | ABST right |        |

      |              +------------+        |

      |                                    v

      v                            +---------------+

+-------------------------------+  | Book          |

| Comparator<Book>              |  +---------------+

+-------------------------------+  | String title  |

| int compare(Book b1, Book b2) |  | String author |

+-------------------------------+  | int price     |

                                   +---------------+

and must satisfy with the following constraints:

Your task is to design classes that represent binary search trees, design some methods for these classes, make these classes accept a visitor — and design the visitor, and finally add a couple of method that are defined only via the visitor.

Here are the details: