View Single Post
  #7 (permalink)  
Old 01-07-2008, 11: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 11:31 PM.
Reply With Quote