We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have homework in programming, and I would like some help with it.
I would like a text input box, where i could type in a single char either l, f, g or h and then the character would be inserted in a string.
My code:
for (x = 0.001; x < 2; x += dx) {
A+=h(x)*dx;
}
println(A);
exit();
As you can see... A+=h(x)*dx; will calculate the function h(x) I would like a popup text box which changes the (h) with one of the other characters, so that it will calculate that instead.
Best regards
And sorry for my rusty english :D
Answers
Your English is okay, but I'm not sure what you're asking. Which part of this are you stuck on? What are you confused about?
Try breaking your problem down into smaller steps. Can you create a small example program that simply shows a text input box and prints out the value the user enters? Can you create another separate example program that simple inserts a String into another String? Keep building example programs from the separate pieces, and when they all work great by themselves, then worry about combining them.
If you get stuck on one of the example programs, post it here and we can help you. Don't forget to use the code button to preserve formatting. Good luck!
it's not as simple as changing one character though. from the description he wants it to use a whole different function (one of 4) based on what the user typed.
so if the user types a g then the sum would be A += g(x) * dx; etc
look at keyPressed() in the reference. have four conditions each containing a different loop, choose based on the key.
I am not sure to understand either. Perhaps show a string before and after, stuff like that.
Not sure what the "popup text box" does there, too. Do you know text() function?
Perhaps he's looking for expression scripting. Something like ScriptEngine w/ JS:
Given he is a beginner doing homework, I doubt it... :-)
koogs got me right. I'm a beginner in programming so I rather prefer a simple method if there is any.
you'll need to repeat the code, unfortunately. something like this:
(^ not real processing code)
(where 'method' is a char variable set according to the key pressed)
We can call function names as String via undocumented Processing function method("").
For example, we can have these 3 functions:
If we wish to call h(), we just issue:
method("h");
For myOtherFunction():
method("myOtherFunction");
And so on and forth... :ar!