I have a function like the following one:
public static double calculateValuationByTransmission(double price, char transmission) {
if (transmission == 'A') {
return price * 0.05;
} else if (transmission == 'M') {
return price * -0.05;
} else {
System.out.println("Transmission must be: 'A' or 'M'");
return 0;
}
}
As you can see this function shows the an error message when the input parameter transmission
does not receive the expected values. Furthermore, it returns 0. I want to use this function in another function as follows:
public static double calculateValuation(double price, int mileage, int age, char transmission) {
if (price < 0.0 || mileage < 0 || age < 0) {
System.out.println("Price, mileage and age must be a positive number");
return -1;
}
//HERE
double valueTransmission = PAC1Ex2.calculateValuationByTransmission(price, transmission);
if (valueTransmission == 0.0){
return -1;
}
double preuIntermedi = price - (valueTransmission +
PAC1Ex2.calculateValuationByMileage(price, mileage));
double preuDevaluacio = PAC1Ex2.calculateValuationByAge(preuIntermedi,age);
System.out.println("Your vehicle is now valued at " + preuDevaluacio +"€");
return preuDevaluacio;
}
However, when I run the code I can see the message but I'm not returning -1. I have tried to match the return as 0.0 and then change it to -1 but this does not work (see code following the //HERE comment). Which one would be the best way to do it?
Thanks in advance