This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# Anyone could explain this script to me?

Renato Bello
Greenhorn
Posts: 15

I don't understand particularly the relation between the two methods (line 13 and the method "maybeNew"). How to calculate it?

If is possible, explain all this script.

Thanks

Gaurangkumar Khalasi
Ranch Hand
Posts: 187

Renato Bello
Greenhorn
Posts: 15
Thank you, GK

I still have some questions:

21 if (index < 5) {

- then the index will always be less than 5 because there is nothing that increments this value?

23 Mix4 m4 = new Mix4();
24 m4.counter = m4counter + 1;

- the total value of m4.counter is infinite and has no use for anything, right?

25 return 1;

- I use the return value of the method maybeNew using the parameter value "index" to add to the value of the variable "count"?

13 count = count + m4a[x].maybeNew(x);

- I still do not understand what is the relationship between M4a [x] and the method "maybeNew". (are in different methods and thought that would relate instance variables with class objects)

Henry Wong
author
Marshal
Posts: 20997
76

Renato Bello
Greenhorn
Posts: 15

Sorry, I thought that the questions was related to the script, I didn't need to identify the parts. Have fix it.

Henry Wong
author
Marshal
Posts: 20997
76
Renato Bello wrote:

Sorry, I thought that the questions was related to the script, I didn't need to identify the parts. Have fix it.

Please click on the link -- and read why we require this. This is not optional.... and BTW, it looks like you quoted the sources for your previous topics, why won't you quote it for this one?

Henry

Renato Bello
Greenhorn
Posts: 15
Renato Bello wrote:Thank you, GK

I still have some questions:

21 if (index < 5) {

- then the index will always be less than 5 because there is nothing that increments this value?

23 Mix4 m4 = new Mix4();
24 m4.counter = m4counter + 1;

- the total value of m4.counter is infinite and has no use for anything, right?

25 return 1;

- I use the return value of the method maybeNew using the parameter value "index" to add to the value of the variable "count"?

13 count = count + m4a[x].maybeNew(x);

- I still do not understand what is the relationship between M4a [x] and the method "maybeNew". (are in different methods and thought that would relate instance variables with class objects)

I am still here with the hope that someone help me with these dilemmas.

Winston Gutkowski
Bartender
Posts: 10236
58
Renato Bello wrote:I am still here with the hope that someone help me with these dilemmas.

And we're still hoping you'll comply with Henry's request. As he said, this is not optional.

Winston

Winston Gutkowski
Bartender
Posts: 10236
58
@Gaurangkumar:

2. Please don't put enormously long lines inside code boxes. It screws up the windowing. I've broken up yours, but please read the UseCodeTags page thoroughly for future reference.

Thanks

Winston

Renato Bello
Greenhorn
Posts: 15
Winston Gutkowski wrote:
Renato Bello wrote:I am still here with the hope that someone help me with these dilemmas.

And we're still hoping you'll comply with Henry's request. As he said, this is not optional.

Winston

I just do not include the reference source because I could not edit the first post. If you can cite the source now, I tell the script that is quoted in the book Head First Java. I apologize again for the fault

Henry Wong
author
Marshal
Posts: 20997
76
Renato Bello wrote:
21 if (index < 5) {

- then the index will always be less than 5 because there is nothing that increments this value?

No. The index is actually passed in as a parameter -- and it does look like the index is incremented by the calling loop.

Renato Bello wrote:
23 Mix4 m4 = new Mix4();
24 m4.counter = m4counter + 1;

- the total value of m4.counter is infinite and has no use for anything, right?

The code creates a new object, whose counter is zero. It gets incremented to one. And then the object is thrown away. Those two lines of code doesn't do anything useful.

Renato Bello wrote:
25 return 1;

- I use the return value of the method maybeNew using the parameter value "index" to add to the value of the variable "count"?

Well, that is what the expression looks like ... see next question.

Renato Bello wrote:
13 count = count + m4a[x].maybeNew(x);

- I still do not understand what is the relationship between M4a [x] and the method "maybeNew". (are in different methods and thought that would relate instance variables with class objects)

m4a[x].maybeNew(x) is part of an expression. It basically says, take the m4a array; deference it to the x element; use that element to call the maybeNew() method, passing the x value as the parameter.

Henry

Winston Gutkowski
Bartender
Posts: 10236
58
Renato Bello wrote:I just do not include the reference source because I could not edit the first post. If you can cite the source now, I tell the script that is quoted in the book Head First Java. I apologize again for the fault

No probs. And BTW, you cited it in your last post: citation is simply stating the source of something.

You'll notice that Henry has now replied to your previous one.

Winston

Renato Bello
Greenhorn
Posts: 15
Thank you, guys

Have some things that I still can not understand, but I'll keep pushing myself, reading the book and posting questions here. Does anyone know if there is a free online course of java?

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Renato Bello wrote:Does anyone know if there is a free online course of java?

The Oracle Java Tutorials are quite good.