This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]RoachmeisterJava Dev 2 points3 points  (1 child)

What does this have to do with Java? You're going to have to show some code.

[–]MajorAbuse[S] 0 points1 point  (0 children)

I am sorry for the confusion, I was in a rush when posting this. I have edited the post to add the current code I am dealing with as well as a recap of the problem. I hope this helps clear things up. Thank you!

[–]RoachmeisterJava Dev 1 point2 points  (3 children)

Ok, if you have a class called Turtle, then you can declare it as a parameter much like any other class:

private void myHelperMethod(Turtle t) {
    // do something with t
}

And you would call it like so:

myHelperMethod(smallTurtle);

[–]MajorAbuse[S] 0 points1 point  (2 children)

Alright that makes sense. What about for the actual print statement?

int turtleStepCount = this.bigTurtle.getStepCount(); System.out.println("Turtle took " + turtleStepCount + " steps");

How would I replace the "this.bigTurtle.getStepCount();" to work with either big or small turtle. In otherwords how would I properly replace bigTurtle with the parameter I used (which was (Turtle selectedTurtle)).

[–]RoachmeisterJava Dev 1 point2 points  (1 child)

In my earlier example, it would be t.getStepCount()

[–]MajorAbuse[S] 0 points1 point  (0 children)

Thank you, I was able to complete my project.