Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Questions on HW5-Spring08

Ask questions on homework 5 here:

Question: Do we have to use private for rootID?

Question: I know how to read the files, do we need 2 buffered readers for the files to read the files?

Question: Do we have to define root other than rootID

Question: How can we use data which has private access in treenode, it gives an error when I try to run it.
public TreeNode getRoot(){return root;}
public void setRoot(TreeNode root){this.root = root;}

Question: I am trying to access the private variable called "data" which is in TreeNode file into my FamilyTree file for the insert method and it gives me an error.
So, how can i do that?

public boolean lessThan(Entry that){ 
return(this.ID<that.ID);

what is this method doing?

When I try to add a person to a new REMOVEDkedList in the FamilyTree constructor, I get the following compiler warning:
"Warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.REMOVEDkedList"
Is this something I should be worried about?

How do I reference the head of my REMOVEDkedList of people? It's called "peopleLL", and I can't get anything like "peopleLL.head" to work.

Also, there doesn't seem to be a getNext() or setNext() method built into Java's REMOVEDkedList, so how do I iterate through the list for my find() method?

when I use new BufferedReader( new FileReader (ppFile) ); I get an error saying that java can't find FileReader and I imported java.io

Question: I'm not sure how to add a new person to the REMOVEDkedList. I already put REMOVEDkedList people = new REMOVEDkedList(), did all the reading in, but I'm not sure how to add them in. I tried Person p = new Person(ID, name, dob, dod, spouse, title) but it says it can't find symbol ID, I also tried just add(new Person(ID, name, dob, dod, spouse, title), with the same error. I know that using the latter approach would require writing an add method, of which I am also unsure.

I'm having trouble iterating down a single line in familytree.txt. I'm using the following code to iterate from line to line:
while ( (line = input.readREMOVEDe()) != null ) {
StringTokenizer mac = new StringTokenizer(line, ",");
Any suggestions as to why this doesn't work to get from name to name within a single line:
while (mac.nextToken() != null) {
?

Why does my find method keep giving me an IndexOutOfBoundsException, despite the following terminating condition:
int count = 0;
while(peopleLL.get(count + 1) != null) {

I'm trying to debug this portion of code; it keeps giving me a NullPointerException. Any suggestions?
BufferedReader input = new BufferedReader( new FileReader( treeFile ) );
String line = input.readREMOVEDe();

while ( (line = input.readREMOVEDe()) != null ) {
StringTokenizer mac = new StringTokenizer(line, ",");

String searchID = mac.nextToken().trim(); //take first ID of the line

while (mac.hasMoreTokens()) {
find(searchID).addChild(mac.nextToken().trim()); //add Child to Person
}

}

Nevermind to the above, I think I found my problem. My find() method is returning null even though there should be a person for every ID. Any suggestions?

public Person find(String findID) {
    for (int i = 0; i < peopleLL.size(); i++) {
      if (peopleLL.get(i).getID() == findID) {
        return peopleLL.get(i);
      }
    }
    return null;
  }


I'm confused about the makeNode() method. The instructions say it's supposed to return a TreeNode, but also be recursive and build the tree. What should the return statement be?

Go Dawn. Thanks for answering questions!

Do we need to show the family tree (call the toString) in the main method or only print the 3 methods (count, depth, and oldest)?

The toString method has to be in a specific order or it just has to display each person in a different line?
There is no specific order. Just every person on a different line. Joel Uthe

Where are the text files going to be saved either on the media source or the java source folder???

Why is the third line of this code:
public TreeNode makeNode(String ID) {
    TreeNode treeRoot = new TreeNode( find(ID) );
    treeRoot.setChildren( find(ID).getChildren() );
giving me this error:
setChildren(java.util.REMOVEDkedList<TreeNode>) in TreeNode cannot be applied to (java.util.REMOVEDkedList<java.lang.String>)
?

Shouldn't it just be passing a REMOVEDkedList of children from the Person to the treeRoot?



Question: I can compile without any errors but when I try to run I get "Interactions terminated by System.exit(1)". It was working fine a minute ago and I didn't change anything in the code. What should I do?

How do we skip lines with a "%"? I cannot figure that out.

I tryed to see if (charAt(0) == '%') to skip the line but nothing is working.

Alright, I'm desperate here. I'm having a problem and can't tell what part of my code is broken. For some reason, count() just returns the number of children in the root node, and I don't know if it's count() that's not working or if I'm not building my tree right. Here's the code in question:
Last line of the constructor: makeNode(rootID);
MakeNode method:
public TreeNode makeNode(String ID) {
TreeNode treeRoot = new TreeNode( find(ID) );
for (int i = 0; i find(ID).getChildren().size(); i++) {
treeRoot.addChild( makeNode( find(ID).getChildren().get(i) ));
}
return treeRoot;
}
Count method:
public int count(String ID) {
int result = 0;
result += find(ID).getChildren().size();
for (int i = 0; i find(ID).getChildren().size(); i++) {
count( find(ID).getChildren().get(i) );
}
return result;
}

Thanks.



Link to this Page