Paul Clapham

Sheriff
+ Follow
since Oct 14, 2005
Paul likes ...
Eclipse IDE Firefox Browser MySQL Database
Merit badge: grant badges
Vancouver, Canada
Cows and Likes
Cows
Total received
88
In last 30 days
0
Total given
158
Likes
Total received
3246
Received in last 30 days
6
Total given
965
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Paul Clapham

Line 25 in the Main class for example.
3 hours ago
You need a variable which keeps track of the "number of times". When you're about to start on another "time" then add 1 to it. Or if that would cause it to exceed the "number of times" then don't start on that next "time".

Since you're creating one of your Carousel object for each "time" (or so I think) it would be easiest to use a static variable.

Or if you're talking about restricting the number of times that run() is called starting at line 13, maybe you could just remove some of those lines to satisfy the number-of-times rule.
1 day ago

Campbell Ritchie wrote:How do you know it is an infinite loop rather than a finite loop running for a very long time?



Let's take the simplest possible non-trivial version of this question: toss a coin repeatedly until you have tossed both tails and heads. The coupon collector's calculation tells us that the expected number of tosses is 3. But for any particular set of tosses, you may only toss twice or you may (if you are more and more unlucky) require any finite number of tosses. The "expected" number is the average number you'll require, not the minimum or maximum.

So the probability that it's an infinite loop is zero, but there is no upper bound on the number of times the loop runs.
1 day ago
Following on from Mike's post: the set of permutations of the numbers in (1 ... N) is exactly equivalent to the set of numbers in (1 ... N!).

So you can greatly simplify your program by starting with an empty set of integers. Then repeat the action of getting a random integer from (1 ... N!) and add that number to the set. Much easier to just select random integers instead of trying to deal with issues with like Collections.shuffle just shuffling a List in place, so that your code only ever has one list where you expected to generate more and more lists.

Note that a Java Set will do nothing if you try to add a duplicate entry, which makes the program even simpler.

There's a mathematical formula which tells you how many times you have to draw repeatedly from the set [1 ... M] until you have drawn all M numbers. You can read about it in Coupon collector's problem although the calculation is non-trivial.
1 day ago

onygen nari wrote:wonder if it is correct



You shouldn't have to ask that. Did you run the code? If not, then run it. Did it output the correct answer? If not, then it isn't correct. If yes, then it might be correct. Keep running it with different inputs until it outputs an incorrect answer or until you believe it's correct.

And remember, your goal in this testing process is to prove that it's incorrect. Try to find unusual inputs which lead to incorrect outputs.
1 day ago
So the subclass would have to contain code which halves instead of decrements. And as I think I mentioned before, that code should really be in its own method so that the subclass could override it without having to duplicate a lot of code from the superclass.
2 days ago

Campbell Ritchie wrote:

Paul Clapham wrote:. . . there was decrementing going on there. . . .

Because OP is using postdecrement, the value retuned is the old value before decrementing.



True, but that's irrelevant to any of the discussion in this thread.
3 days ago

Cris Marinescu wrote:How can I replace my code from next() in order to have the right result?



You would have to ask somebody who knew what "Decrementing" means in "DecrementingCarousel". I looked at the code and there was no hint of that. My guess was that the "decrementing" was this code:

but only because there was decrementing going on there. Otherwise there was just code fossicking around in an array for no reason I could determine.

You may feel that I am being over-critical of your code. On the contrary, it's the documentation of the code that I'm criticizing. I see nothing which says what it's supposed to do, nor any comments in the code which say what it is actually doing.
3 days ago
If your query is constant, e.g. SELECT that, that, theother from SOMETABLE, then a Statement is fine. But if your query requires parameters, like in your example, you should use PreparedStatement. That not only means you don't have to know how to format Strings and Dates and Times and so on for your database, it also protects you from SQL injection attacks.

Even formatting Strings isn't as simple as you might guess. Yes, you have to put quotes around them to make valid SQL, but if the String contains a quote (like a user named O'Brien) you have to escape that quote in the way your database wants it escaped. This can get to be a real pain, but PreparedStatement takes care of all that tedious stuff.
Hint: Find the method which decrements something, and override it with a method which halves that thing.

But this immediately leads to the question, that code is embedded in a method which does a lot of other stuff unrelated to decrementing or halving. You don't want to duplicate all of that other stuff. So the first step is to fix the code so that decrementing the something is done in a separate method. That makes it easy for the subclass to just override that separate method.

There's also the question of why you have to override DecrementingCarousel by HalvingCarousel. You really shouldn't. A HalvingCarousel is in no way a DecrementingCarousel, since a D--C-- is based on decrementing things and a H--C-- is not. It would be better to have an AbstractCarousel superclass which contains all of the machinery except the bit which modifies a value, and then create the two subclasses D--C-- and H--C--,
3 days ago
If you had used a PreparedStatement, though, you wouldn't have to concern yourself with that sort of details.


First of all: have you confirmed that those lines of code are actually executed?

And do your specifications really require you to use "Brith" for what to me appears to be "Birth"? Sorry, I find that so distracting that I have trouble looking at your code.
1 week ago
You know what version 1 does, and it does what you need. But you aren't sure about version 2. So just use version 1.

Ben Matthew wrote:Raven Reader is good but accepts only RSS FEED URL and not text files..So how to use that app when i have only text files with me....



Your question sounds like "Raven Reader doesn't accept text files. So how do I use it for text files?" Is that actually your question, or have I misinterpreted?
1 month ago

Ben Matthew wrote:Tim, facing mysql workbench installation issues.



If you want to do reverse engineering for MySQL, then don't give up on installing the workbench. Maybe you already searched the web for how to reverse engineer a MySQL database and noticed that the workbench was mentioned frequently. That's because it's the obvious tool to use. In fact in my brief web search I didn't find many other tools mentioned, and the ones I did find are complex and not-free products. So go back and work on those issues.