How is the Irrational class setup?
I'm assuming it's something you created yourself, since i've never personally encountered it.
If Irrational is another class you created, there really isn't much use in it since you can just use doubles (or BidDecimal for higher precision) instead directly.
So instead i will answer your quesions using doubles for simplicity:
In your MIrrational you have this:
Code:
public double add(double t, double z) {
return t+z;
}
Usually the form you would use to call this method is by creating an instance of the object that contains the method first. Like this:
Code:
MIrrational myObject= new MIrrational();
double t= 1.2;
double z= 2.3;
double return = myObject.add(t,z);
...
So in your case you would need to read 2 doubles and then pass 'em to the function and hold the result for display to user.
Another approach would be to have the add method in the same class as your main. Then you won't need to actually create an instance of the object and will just be able to do "add(t,z);".
Finally, if you must use a method from another class, then you can make it static, by doing:
Code:
public static double add(double t, double z) { ... }
This time you would need to specify where the method is coming from, but don't need to create an object of that type:
Code:
result = MIrrational.add(t,z);
Hope this helps.