Jan Hoppmann

Ranch Hand
+ Follow
since Jul 19, 2010
Jan likes ...
Android Eclipse IDE Linux
Germany
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
11
Received in last 30 days
0
Total given
8
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jan Hoppmann

My approach seems to be a bit more naïve (and rather long):

4 years ago
I had a similar problem a while back (computing probabilities for an arbitrary number of different dice (with arbitrary number of sides), and am interested in how you solved this
4 years ago
I have to say that I have difficulty following your code. For starters, compDate1 through 3 are not good names for variables. Why not something like birthdate, zodiacStart, zodiacEnd or something like this? That would make the logic in line 49 much clearer. And why do you parse the year of date in line 36, only to throw it away in line 45?
4 years ago

Monica. Shiralkar wrote:

Do we have to create object of Abc abc=new Abc() as class variable and then set the value as above or this object should be created inside the method and then value is set?



I'd say the way you're doing it now is right, but it really depends on your requirements.

If the value is meant to be part of the state of the object at creation, you can set it in your constructor. But if it is likely to change (or is meant to be changed), the setter / getter you're using now seems right.
4 years ago

Edwin Torres wrote:You can use threads. In this example, a thread does the querying (simulated), sleeps 10 seconds, and repeats. The thread ends when you call interrupt(). Here's the code:



That's the way I solved problems like these before using the Timer / TimerTask. Are there any potential downsides to this? I think code like this is in a no-longer maintained program of mine that might or might not run on a client's server ;)
4 years ago

Duncan MacFarland wrote:I am trying to put a reference to a given subclass object into a linked list, and then come back later, and invoke a method of the subclass object that is in a given spot in the linked list. This produces an error because Object does not have that method. Is it necessary to cast the object to the correct subclass every time I want to use one of its methods, or is there a way to convince the JVM to treat it as always of type MySubclass? Thanks.



I'm not sure if Pawel got your problem.
Is it something like you have a class A, a subclass of A named B, and a LinkedList, but want to insert an object of B at position, say, 5, and want the JVM to know that this is of type B, not A?
5 years ago

John Brendan wrote:Could you write me the code so I can test in Eclipse please?



There is no code involved. Both of these links are for tools, not code. YOu need to start / install them. And the links should provide you with all the info you need to do that.
5 years ago
Yay! This is the second time in my life I won anything
Thanks!
5 years ago

Mark Do wrote:Ok.......I cant still seem to figure out how or where to put the for loop so that the whole array will loop 1024 times! someone help! thanks!



You edited your code after my reply. It looked good before; you looped 1024 times over the loop that flips the five coins - that is exactly what you wanted, is it not? I don't see why you changed it. Did it produce weird results?
5 years ago
This looks good so far. You're forgetting to clear your output string and the tailscount in the outer loop.

What doesn't work now (except the things I mentioned above)? How would you do what doesn't work if I gave you a pen, a piece of paper and 5 coins?
5 years ago

Mark Do wrote:I want to toss 5 coins as a group



Well, you have your array of five coins. How would you flip these 5 coins now?
5 years ago
The definition and initialization of the array and its elements is right, but it is not in the right place - it seems to be in the Coin class itself, while your assignment states that you should use a driver class for this. Just move lines 1 - 9 there and you should be fine.
5 years ago

Campbell Ritchie wrote:Welcome to the Ranch

Reread Jan Hoppmann's post, which gives the correct answer. If there is any of it you can't understand, please tell us and we'll try and explain it. I think lost plausible is an unusual spelling of most plausible



I corrected that. Yes, you're right
5 years ago
I have to guess here, but I'd say every time you initialize a new object of Foo, it gets a new instance of id. Since id is counter++, the static counter is incremented each time you access it this way. This seems the most plausible explanation to me.
5 years ago
We could help you better if we knew something more about the internals of SimplePublicPair and SimplePublicTriple.
But normally, you shoud just take a and b from the SimplePublicPair object, multiply them, and store the result somewhere. Afterwards, you pass this three variables into the constructor for SimplePublicTriple. If it has only the default constructor, or none that takes three arguments, perhaps there are setters.
5 years ago