Question: Homework 7 - Encapsulating Node with GPTree Points badge It s time to plan ahead for the Genetic Programming project. If we try to process

Homework 7- Encapsulating Node with GPTree
Points badge
Its time to plan ahead for the Genetic Programming project. If we try to process more trees in our main() method, it will get unwieldy and hard to maintain. A simplistic rule of thumb is that main() shouldnt have more than about 20 lines of code in it. It should make a few objects, and then tell them to "go about their business."
Starting Out:
Copy the files from your completed Refactoring project to this directory
After you copy the files, only two of the copied files should be modified
Node.java - to add concrete methods traverse(), swapLeft(Node trunk),swapRight(Node trunk), and isLeaf().
Divide.java - to fix division by zero.
The task
One way to add useful encapsulation is to create a GPTree class that consolidates some of the functionality of trees. Currently, the Node class knows how to do things, but a tree class that encapsulates the root node of a tree will be useful. This process has five steps.
Step 1 The Node class will be modified to have a traverse(Collector c) method that will recursively give Nodes in the Tree to the Collector interface to collect them. That way, a list of potential binary Nodes will be held by the GPTree to be randomly selected as crossover points.
Step 2 You will add 3 new files to this project, Collector.java, GPTree.java and TestGPTree.java described below.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!