wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Rules declaration in text file - please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rules declaration in text file - please help" Watch "Rules declaration in text file - please help" New topic
Author

Rules declaration in text file - please help

Andra Pande
Greenhorn

Joined: Jul 16, 2009
Posts: 3
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

Joined: Oct 02, 2003
Posts: 11160
    
  16

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?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Andra Pande
Greenhorn

Joined: Jul 16, 2009
Posts: 3
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

Joined: Oct 13, 2005
Posts: 38007
    
  22
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

Joined: Oct 02, 2003
Posts: 11160
    
  16

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

Joined: Oct 13, 2005
Posts: 38007
    
  22
What about a Map where you enter Strings as keys and objects incorporating the actions as values?
Andra Pande
Greenhorn

Joined: Jul 16, 2009
Posts: 3
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
 
subject: Rules declaration in text file - please help
 
Similar Threads
[SWT] resize problem
Custom tag scenario
problem with inhereitance
How to modify HTML content on a JTabbedPane using JD Native Swing libraries
Get a single line from a String Buffer