It ain't ruby !!
You can achieve this using call back, mess of codes ..
public class Main {
double initialCost ;
CostCalculator cost1 ;
CostCalculator cost2 ;
Main(){
cost1 = new CostCalculator(){
@Override
public double Calculate(double initialCost) {
return initialCost * 2 ;
}
};
cost2 = new CostCalculator(){
@Override
public double Calculate(double initialCost) {
return initialCost * 3 ; // What ever
}
};
}
public double calculate(){
return cost1.Calculate(initialCost); // Plus extra stuffs if you have
}
}
If i have understood your problem correctly, this is one of the option you have got.