File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rules declaration in text file - please help

 
Andra Pande
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have a problem with my Java program.
I already have some rules written in Java like these:
code 1

I want to declare that rule in a text file so people
don't have to understand Java if they want to add
some new rules. It became like these:
code2

which means just like code1.

What make me confuse is,
how to write a Java code that able to read the rules in text file
and transform it become if-else rules in java code?

Thanks for your help
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't think this is a trivial problem. It requires you to define your language of how the user will define the conditions, and how they will define what to do. you have to define WHAT they can do... i mean, if a == b, do they open a web page? do they display a .gif? does it then ask for them to input their age? does it compute their taxes? does it play a game of Go?

 
Andra Pande
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already define the language and what the program will do.
What made me confuse is how to code a program that will transform
the rules in text file become if-else condition in Java language.

For example, as you can see the rules in text file are just like:

I want the Java program to read it as:

Can you give me some example code?

Btw, thanks for the quick reply
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch
Andra Pande wrote:
I want the Java program to read it as:
No, you don't. You don't want to use the == operator there. Look at your first post where you correctly used equalsIgnoreCase. And remember the difference between & and &&.

Can you give me some example code?
No. We expect people to work out their own code, not being a place where code is produced. You have already posted code which would work, and been given a criticism of that approach.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as a broad hint... you'll need to code everything by hand. each thing should probably be in it's own method, where you pass in various parameters. then, you're if-then-else would call the proper method with the proper arguments.

Note: this may not be the BEST approach, but it's one that will work, and would be a good start.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about a Map where you enter Strings as keys and objects incorporating the actions as values?
 
Andra Pande
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your advice guys

I think I'll try what Fred said
I'll report back whether I success or fail
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic