Results 1 to 5 of 5
Thread: create a formula from a string
- 07-17-2008, 12:41 AM #1
Member
- Join Date
- Jul 2008
- Posts
- 3
- Rep Power
- 0
create a formula from a string
Hi im doing this statistical program where i want the user
to be able to make hes own formula and pass it to the program.
i am able to get it from a jlabel to a string, but i cant use the string
as a mathematical formula..
im supposed to use tokens (so i heard),
but i dont know how ??
can anyone help me, i want to have it as simple as possibly by the way,
because i am new at java so this is a kind of learning program for me.
thanks guys and gurls
- 07-17-2008, 01:02 AM #2
Formulas
Hello lemon3. :)
I wrote I program in C# that can parse (meaning to decode from a string) basic mathematical formulas and then calculate the answer step-by-step while keeping the order of operations correct, e.g. multiply and then add, etc. It could also handle brackets. So the user would input
and the program would giveJava Code:1 + 5 * (1 - 3 / 3)
If this is what you want to do, then it will take some time to create such a system. The parsing and execution is the hardest bit but this is still a large undertaking when starting from scratch.Java Code:1 + 5 * (1 - 3 / 3) = 1 + 5 * (1 - 1) = 1 + 5 * (0) = 1 + 5 * 0 = 1 + 0 = 1
Unfortunately, my code is in C#, so it would not help much.:oEyes dwelling into the past are blind to what lies in the future. Step carefully.
- 07-17-2008, 03:29 AM #3
That sounds like a difficult way to do it. Reading in an expression as a string and then parsing it is not trivial!! I'd suggest that you simplify and restrict the user input in some way so that it doesnt' require parsing. For example use a form with mulitple text input areas and operand selections. Or find someone else's code that will do the parsing and evaluation and use that.
There was a student looking for a project on one of the forums. Find him and see if he will do it.
Look at:
SourceForge.net: FilesLast edited by Norm; 07-17-2008 at 07:03 PM.
- 07-18-2008, 12:33 AM #4
Member
- Join Date
- Jul 2008
- Posts
- 3
- Rep Power
- 0
thanks for your help, i found some evaluation program called jel
i will try to use that one . thanks
- 07-18-2008, 09:24 PM #5
Similar Threads
-
Computing the area of a triangle using Heron's Formula
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:39 PM -
How to create object dynamically with class name known in string format
By ranu_gokhe in forum Advanced JavaReplies: 1Last Post: 04-09-2008, 02:15 AM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM -
What is the formula?
By yuchuang in forum New To JavaReplies: 3Last Post: 04-30-2007, 10:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks