Piet Souris

Master Rancher
+ Follow
since Mar 08, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Piet Souris

Hi David,

Welcome to the ranch and enjoy the stay!

A combobox has the method 'getSelectedIndex' that will give you an Int.  See the API.
4 hours ago
Since we need to test all digits of some  number, I would start thinking about a way to get all those digits. You are using n % 10, that gives the last digit. So far so good. But how next to obtain the last but one? If you have this, then you're almost done.

Something about programming style. I agree with  Campbell that 'isEven'  is a better name than just 'Even'. The difference being that when you call this method, then 'if (isEven(n)) ...' just reads a bit more pleasant than just 'if (Even (n)) ...' , but admittedly this is subjective.

Then, it is important to be very clear about what a method does and what parameters are involved. Look again at 'Even'. Does this method tests the input for being even, or should it test if all digits of the input are even? And does it test any number, or just a single digit? If a single digit, then why not call the method 'isEvenDigit?

But don't worry, it will come with increasing knowledge and experience, give it some time.
4 hours ago
Indeed it was similar.

It would be handy to assign each subcalculation to a variable, so that you can print out that variable to check if it is what you expect it to be.
So in Even, you could write

Then try n = 5 and see if Even reports an even or an odd result.
8 hours ago
Hi Allen,

welcome to the ranch and enjoy the stay!

Yes, it sounds allright. Problem to solve is getting the individual digits. Do you have an idea how to do that? And o yeah, as soon as you find an odd digit, you can stop the process. Why?
10 hours ago
And also, how often is 'new Thread(new Runnable() {...} invoked?
Every time it creates a new Runnable in diggingHandler.post (whatever that is). Put a static counter there.
19 hours ago
You're welcome!
20 hours ago
Hang on a bit.. I get what you want to achieve. The user is supposed to guess z of the equation. Silly me!

Well, you can make a loop that continually makes a new Repose(), asking the user to enter a value for z, unti the user has had enough. So there are some things that must be done.

1) creating a loop that asks if the user would like to have another go. You can use a Snanner for this. This can be done in main() of Reponse.
2) if the user wants another go, create a new Equation instance, that will print the equation. Mind you, as it is now, you print the whole equation, including z! That kinda makes it rather easy to solve....
3) Then determine the correct solution,  what you have now fixes the correct answer to option d. Try to think of a way to get the correct answer at random also in a, b or c. You can use the same Scanner for this.
4) Start some festivities when the user gambles correct, or tar and feathers should he/she fail.
5) And repeat

Let us know if you have any difficulty in the implementation.

Edit: it took me some time to type all of the above. I see there has been some other posts going on. I hope what I wrote has still some value
20 hours ago
hi Thomas,

welcome to the Ranch and enjoy the stay!

It is me a little unclear as to what the purpose is of the classes Equation and Reponse, so perhaps you can elaborate a bit.

In the class Reponse, you make an instance of Equation, that determines x, y , z and an operator op such that x op y = z. Okay, you then display that equation,. Next, you determine a value for a, or b, or c, or d.
And then? What is supposed to happen next? Must a user make some guess? And if so, what guess?
20 hours ago
In the first case (Thread.sleep(100)), you let the Tread sleep for one tenth of a second. Now, when you only had 100 Runnables, that 100 milliseconds was enough to have 'service' process them all. However, in the case of 100_000 or even 1_000_000 Runnables, this was no longer the case, so that the printout happened before service was finished. The printout thus showed some intermediate values.
In the second case, I let the Thread wait until the service was terminated, in which case we know for sure that all Runnables were completed, no matter how much time that would take. I let it wait for max 5 seconds, so in theory I should have checked after 'awairtTermination' if the service had indeed terminated or that the 5 seconds simply were over.

I hope the difference is clear.
There was so much talking about regex and split, that I was uncertain what to do with the lines-to-be-saved. So I mentioned it savely 'splitAndSave', but I understand that no splitting is needed, that makes it easier. Sorry for the confusion. You don't now need a separate method. If you have an ArrayList<String> linesToSave, you can simply add each line to it when 'afterDuration' is true, instead of calling that method.
21 hours ago
In my first reply I hinted to this:

I don't understand why this simple code wouldn't at least be worth a try.
1 day ago
But you can create a class PurCust with fields Purchase and Customer. First make a map <Long, Customer> with key CustomerID, and for every Purchase create a new PurCust instance, by looking up the CustomerID of the Purchase in the map.
Then do as Stephan described.
1 day ago
But must you use a regex? Can't you use String.contains or String.startsWith?
1 day ago
Exactly what I meant.
2 days ago
I'm not sure why String.split must be used at all. If you have a BufferedReader, and you read in line by line, maintain a boolean 'beforeDuration', and only store the lines when that boolean is false. An ArrayList might be handier than an Array. Or did I misunderstand something?
2 days ago