• Post Reply Bookmark Topic Watch Topic
  • New Topic

Public class LightController help please  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If some one can point me in the right direction for this code for my assignment I would really appreciate it. I have tried my best but I'm getting no where.

im confused on the public void grow(int size) method. at first i thou of doing a while loop, but im not getting anywhere tbh. i think its the fact that i dont know what size is. i think im confused. if someone could just start me off with the method or explain to me what the question is trying to say regarding the argument size as after this method i have a couple more which are similar that i ned to do too.

>Now complete the public instance method `grow(int size)` that causes the circle referenced by the instance variable light to expand.
The argument, `size`, is an int that represents the new diameter of the `Circle` object referenced by the instance variable `light`. You can assume that `size` will always be an even number that is bigger than the current diameter (50) of the `Circle` object. In order to get the correct effect, you should use a loop within which the circle referenced by light expands its diameter in steps of 2 and its `xPos` and `yPos` decrease in steps of 1, until diameter reaches the value of size. At each step the object referenced by light should randomly change its colour.

 
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
zafreen iqbal wrote:If some one can point me in the right direction for this code for my assignment I would really appreciate it. I have tried my best but I'm getting no where.

im confused on the public void grow(int size) method. at first i thou of doing a while loop, but im not getting anywhere tbh. i think its the fact that i dont know what size is. i think im confused. if someone could just start me off with the method or explain to me what the question is trying to say regarding the argument size as after this method i have a couple more which are similar that i ned to do too.

>Now complete the public instance method `grow(int size)` that causes the circle referenced by the instance variable light to expand.
The argument, `size`, is an int that represents the new diameter of the `Circle` object referenced by the instance variable `light`. You can assume that `size` will always be an even number that is bigger than the current diameter (50) of the `Circle` object. In order to get the correct effect, you should use a loop within which the circle referenced by light expands its diameter in steps of 2 and its `xPos` and `yPos` decrease in steps of 1, until diameter reaches the value of size. At each step the object referenced by light should randomly change its colour.

You have a circle that starts out with some known diameter. Size will be the diameter when the looping is complete. You will loop in increments of 2 for the diameter and -1 for x and y pos. You will add a delay after each increment. So, you do know what size is. I would suggest writing down the steps in English (or your native language) first before writing any code.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are planning to use that in a Swing application do not use Thread.sleep. You would have to find some other way to create the delay, possibly with a Timer object. Beware: there are two Timer classes.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there are three Timer classes.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Greenhorn
Posts: 18
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am not sure what the OUColour is suppose to be? I assume OU is from a class library?
I put the 'this' keyword into the code since you would have declared these (int xPos, int yPos) as instance variables.
 
zafreen iqbal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all your help, i missed out the class Circle which is also very important. sorry about that.

In the Class LightController i have only 2 instance variables.
n yes OU is from the class library.

im doing a for loop for this, but dont knw if it will work.
eg;
for (int diameter = 50; diameter < size; diameter++)
etc.
i dont know if im going the right way though


 
Matt Matthews
Greenhorn
Posts: 18
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You say you only have two instance variables for the LightController class but in your constructor you are calling xPos,yPos etc. Won't that give you compilation errors since those instance variables don't actually exist in your class?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use aDiameter for the name of the parameter; it is poor style and awkward to read.You are already using this. so there is no risk of confusing the parameter with the field. I would suggest this enhancement to prevent anybody trying to pass a negative size:-The header for the loop looks all right, but you realise it will never run if size is not greater than 50. Whether it works or not depends on the contents of the loop, which you haven't shown us. Thread.sleep() will not work at all well if you are using Swing.

Don't double‑space the code and be careful about spellings; both things can make the post harder to read especially for people who didn't grow up speaking or reading English.
 
zafreen iqbal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, and sorry about the English.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome and apologies accepted
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!