Results 1 to 2 of 2
- 12-08-2009, 11:27 PM #1Member
- Join Date
- Dec 2009
- Rep Power
declare a private instance variable called ran of type random
Could someone plese help me with this problem?
how do I
declare a private instance variable called ran of type random. Then add a line to the constructor to create an instance of random, using the random class's zero-argument constructor, and directly assign it to the instance variable ran.
any help would be great thanks :)
- 12-09-2009, 12:57 AM #2
Can you show us your code? Declaring a new Random variable is the same as declaring any other type of variable.
Likewise, you can create a new instance in your constructor like you would for any other data type.
I mean, your request details the code steps to take.
1) declare a private instance variable called ran of type random
2) add a line to the constructor to create an instance of random
2a) use the random class's zero-argument constructor
2b) directly assign it to the instance variable ran.
Which of the above steps are you having trouble with? Without giving the five line or what not solution, I can't imagine what kind of assistance to give without seeing what code you already have.
If you present the code you have, we can offer suggestions and help you with any questions you may have.
In most cases, you shouldn't need an instance variable for Random, but instead should only need a class variable. Is there a reason you need a separate Random instance for each instance of your class?
Last edited by CodesAway; 12-09-2009 at 01:01 AM.CodesAway - codesaway.info
writing tools that make writing code a little easier
- By blaklite in forum New To JavaReplies: 2Last Post: 03-25-2009, 12:56 AM
- By pikalex88 in forum New To JavaReplies: 3Last Post: 09-30-2008, 06:27 PM
- By javarishi in forum Java ServletReplies: 3Last Post: 06-14-2008, 08:28 AM
- By barney in forum New To JavaReplies: 1Last Post: 08-06-2007, 02:17 AM
- By Jack in forum New To JavaReplies: 2Last Post: 07-04-2007, 04:00 AM