Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-07-2008, 09:20 PM
Member
 
Join Date: Jun 2007
Posts: 14
bluekswing is on a distinguished road
Quick Stupid Question
Would the following code work? (I know I could test it out and will when I'm in front of a computer that has eclipse/netbeans. I'm currently at work and just don't have access to any programming environment and the curiosity is killing me!!!)


So to satisfy my curiousity


public class Test {


public static void main (String[] args) {


int x = 10;
int y = 9;
String condition = ">";

if (x condition y) {

System.out.println("This works");

} //end if

} //end main

}//end class


Thanks a bunch for the help!

Last edited by bluekswing : 01-07-2008 at 09:24 PM. Reason: Added semi-colons
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-07-2008, 09:22 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Doesnot work .. where is semicolon .. the condition thing you are using is not accepted in java..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-07-2008, 09:32 PM
Member
 
Join Date: Jun 2007
Posts: 14
bluekswing is on a distinguished road
Thanks roots! Ugh - I thought I finally nailed a problem I've been having.

I'm trying to create a list of "IF-Then" conditions regarding some varibles for java to check. I want to be able to dynamically create these conditions and not hard code them in some class. I'm attempting to create "rule objects" that can be stored in some List data structure and can be executed when needed.

I"m having a terrible time figuring out how to construct such an object. ANy thoughts or suggestions?

For example, I want one of the rules on the list (rule object) to be "If x > y add 1 to sum". Any thoughts suggestions?

Thanks again for the help!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-07-2008, 09:55 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Looks Something kinda Expression Parser.. pseudo language .. You can implement custom expression parser ..

Can you list more of examples of such expressions .. possible expressions ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-07-2008, 10:11 PM
Member
 
Join Date: Jun 2007
Posts: 14
bluekswing is on a distinguished road
Hmm interesting....I"ll have to read up more on expression parsing.


Essentially I have an object that has 50 variables either of type String or type int. Everyday I want to be able to run a test on the object's instance variables based on a set of conditions. These conditions can change from day to day.

All the rules will be of an "if- then" format. So,

//If variable1 = variable2 then add 1 to total sum
//If variable8 > variable3 then add 2 to total sum
//If variable23 >= variable27 then subtract 0.5 from total sum
//If variable19.equals(variable5) then add 0.25 to total sum


So essentially every rule will contain some comparison between two variables where any of the following equality conditions apply: (> , < , = (.equals) , != , =<, >=)



The stumbling block for me is how to create these rule objects.......
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-07-2008, 10:26 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Code:
public static Object eval(String expression, Object... variables ){ // Refer introductory compiler mechanisms }
Have a quick look at compilers .. that should get you started ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-07-2008, 10:29 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Comparison class
Hello bluekswing.

Why don't you just create a class that can compare two Double numbers. For example:
Code:
public class NumberCompare{ public enum TOperation {equals, greater, smaller, greaterOrEqual, smallerOrEqual}; private TOperation operation = TOperation.equals; public void setOperation(TOperation operation){ this.operation = operation; } public TOperation getOperation(){ return this.operation; } public boolean compare(Double first, Double second){ switch (operation){ case equals : return first == second; break; case greater: return first > second; break; case smaller: return first < second; break; case greaterOrEqual: return first >= second; break; case smallerOrEqual: return first <= second; break; default: return false; } } }
Now you can create a single NumberCompare object and change its operator as you need. Then you can call its compare() method. You can create a similar class for preforming the calculations. You can do the same for String objects.

This code has been checked by hand. I hope this helped.
__________________
If your ship has not come in yet then build a lighthouse.

Last edited by tim : 01-07-2008 at 10:31 PM.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-08-2008, 07:35 PM
Member
 
Join Date: Jun 2007
Posts: 14
bluekswing is on a distinguished road
Thanks Tim and roots for the replies. You have given me much to think about....
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
a really stupid question SwinGirl NetBeans 10 06-25-2008 10:06 PM
Wanna make 5 quick bucks? GodiaN Java Applets 5 01-21-2008 08:15 PM
Quick Help Please! Can't Run Code!! VinceGuad Eclipse 4 01-16-2008 04:54 AM
Quick Job required in Java taxman Jobs Offered 0 01-02-2008 12:46 PM
Quick Question (Functions) ibanez270dx New To Java 2 11-16-2007 02:42 AM


All times are GMT +3. The time now is 11:30 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org