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
Ho Sun Lee
2,003 PointsA 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:
Write the first line of a method named zool that takes three parameters: an int and two Strings.
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!
Ho Sun Lee
2,003 PointsHey 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
Treehouse TeacherHo;
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
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherHey Ho!
We haven't talked about methods yet, and I am glad you are cruising ahead. In the main method, you call, or invoke,
zoollike Ken Alger says.Note that in your
zoolmethod you are resetting thosevariables,age,petandhouse. You should pass those in as arguments to yourzoolmethod. Basically that will set thosevariablesyou declared.Lose the first 3 lines of your
zoolmethod, and call it from themainmethod and you are golden!Good work!