• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anyone could explain this script to me?

 
Renato Bello
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Renato Bello
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
 
Renato Bello
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:Please QuoteYourSources.



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
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Renato Bello wrote:
Henry Wong wrote:Please QuoteYourSources.



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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10087
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10087
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Gaurangkumar:

1. Please don't provide ready-made solutions. We are NotACodeMill (←click).
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10087
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Renato Bello wrote:Does anyone know if there is a free online course of java?

The Oracle Java Tutorials are quite good.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic