Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

A quick Java question

Hi everyone (or anyone that's willing to read this post)!

So I have an exercise problem from my book "Think Java" (kudos to whoever recommended this book, it was someone on the forums) that I'm having some trouble with.

Here is the problem:

  1. Write the first line of a method named zool that takes three parameters: an int and two Strings.

  2. Write a line of code that invokes zool, passing as arguments the value 11, the name of your first pet, and the name of the street you grew up on.

This is what I started with (I'm probably wrong here):

public static void zool (int age, String pet, String house) {
    age = 25;
    pet = "Benji";
    house = "91 Linhaven";

    System.out.print("I am " + age + " years old");
    System.out.print("I have a dog named " + pet);
    System.out.print("I grew up in  " + house);
}

public static void main(String[] args) {

}

I don't even know if I did the first part correctly, and I'm having some trouble invoking zool. Can anyone help me out?

Thanks in advance!

Craig Dennis
Craig Dennis
Treehouse Teacher

Hey Ho!

We haven't talked about methods yet, and I am glad you are cruising ahead. In the main method, you call, or invoke, zool like Ken Alger says.

Note that in your zool method you are resetting those variables, age, pet and house. You should pass those in as arguments to your zool method. Basically that will set those variables you declared.

Lose the first 3 lines of your zool method, and call it from the main method and you are golden!

Good work!

Hey Craig!

Thanks for the words of wisdom, I thought I was over thinking this a little too much, very glad that you and Ken came to my rescue.

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Ho;

For the purposes of the exercise in the book I don't see where you need to get as involved as you did.

For question 1: Write the first line of a method named zool that takes three parameters: an int and two Strings. It is asking you to do just that, just write the first line of a method with those related instructions. So, you could do something like:

public static void zool (int foo, String bar, String baz) {}

If that were a Treehouse challenge I would think that would pass for the method definition, or first line.

Question 2: Write a line of code that invokes zool, passing as arguments the value 11, the name of your first pet, and the name of the street you grew up on. Can be as equally simplified to exactly what it is asking.

zool (11, "Rocky", "Pillsbury");

You can certainly create zool to do something, but I think for the purposes of the book's exercises, that is all that is necessary.

Happy coding,

Ken