Question: 1 . Download the following class source files: DevisionTree.java TextDecisionGame.java TextDecisionGameBuilder.java TreeNode.java 2 . In Eclipse, create a new Java project called Project 2

1. Download the following class source files:
DevisionTree.java
TextDecisionGame.java
TextDecisionGameBuilder.java
TreeNode.java
2. In Eclipse, create a new Java project called "Project 2", and import the above 3 files.
3. Both TextDecisionGameBuilder.java and TextDecisionGame.java have main methods.
TextDecisionGameBuilder is the one that will help you to build your games. This will
compile and correctly run without further modification.
4. Using TextDecisionGameBuilder, generate 3 of your own text-based games. Each game
should have at least one path to completion that is at least 5 scenarios deep
5.Analysis the recursive methods recursiveBuildTree, recursiveSave and recursiveLoad in
the class DecisionTree and gain an understanding of how the trees are is built. Generate
a visual representation in tree form of the order in which each node is created. Put a
number inside the node to denote the order (you do not need to put the scenarios in
6. TextDecisionGame is the second program with main, and this is the actual game
launcher. When you run it, it will ask for a save file you created with
TextDecisionGameBuilder. In order for it to work, you need to implement the method
play() inside the DecisionTree class. This method is NOT recursive. You will use a loop,
and ask the user what option they wish to choose... moving a traverse pointer to the next
node in the tree based on the users choice. (example: trav=trav.getOption1() or
trav=trav.getOption2()
public class TextDecisionGameBuilder {
public static void main(String[] args){
// TODO Auto-generated method stub
DecisionTree d = new DecisionTree();
d.buildStory();
d.saveTreeToFile();}import java.util.Scanner;
public class TextDecisionGame {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
DecisionTree dt = new DecisionTree();
char choice;
do{
System.out.println("What file your you like to load?");
String filename = input.nextLine();
//Load up a game from the text file
dt.loadTreeFromFile(filename);
//Beginning playing.
dt.play();
do{
System.out.println("Would you like to play again?");
choice = input.nextLine().charAt(0);
}while((choice !='n')&&(choice !='N')&&(choice !='Y')&&(choice !='y'));
}while(choice =='Y'|| choice =='y');} import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class DecisionTree {
private TreeNode head = null;
Scanner input = new Scanner(System.in);
public void play()
{
//Fill in code here
}
public void buildStory()
{
head = recursivelyBuildTree(new String());
System.out.println("The Story Is Complete!");
}
private TreeNode recursivelyBuildTree(String storySoFar)
{
//Reiterate the story so far....
System.out.println("The story so far...");
System.out.println(storySoFar);
//Create a new node
TreeNode newNode = new TreeNode();
//Find out if this is an end to the story
char choice;
do{
System.out.println("Is this an ending node? (y/n)");
choice = input.nextLine().charAt(0);
}while((choice !='n')&&(choice !='N')&&(choice !='Y')&&(choice !='y'));
//Set the newNode to reflect if it's an ending...
newNode.setEnding(choice=='y'|| choice=='Y');
//Get the text for this segment
String temp;
do{
System.out.println("What is the text for this section of the story?");
temp = input.nextLine();
System.out.println("Are you okay with this?(y/n): "+ temp);
choice = input.nextLine().charAt(0);
}while((choice =='n')||(choice =='N'));
//Set the newNode to reflect the new text
newNode.setMessage(temp);
//Recursively call recursivelyBuildTree if this is not an ending...
if(!newNode.isEnding())
{
newNode.setOption1(recursivelyBuildTree(storySoFar+temp+'
'+"Option 1 chosen"+'
'));
newNode.setOption2(recursivelyBuildTree(storySoFar+temp+'
'+"Option 2 chosen"+'
'));
}
return newNode;
}
public void saveTreeToFile()
{
System.out.println("What would you like your file name saved as?");
String filename = input.nextLine();
//Create file
try{
PrintWriter pw = new PrintWriter(filename);
recursiveSave(pw,head);
pw.close();
}catch(FileNotFoundException e)
{
System.out.println("File not created! Issue creating file: "+filename);
}
}
private void recursiveSave(PrintWriter output, TreeNode currentNode)
{
//Save the text from this node
output.println(currentNode.getMessage());
//Save whether or not this is an ending node
output.println(currentNode.isEnding());
//if this is not an ending, we need to go deeper
if(!currentNode.isEnding())
{
recursiveSave(output,currentNode.getOption1());
recursiveSave(output,currentNode.getOption2());
}
}
public void loadTreeFromFile(String filename)
{

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 Accounting Questions!