• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Rules declaration in text file - please help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic