You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

32 lines
882 B

class CouponRateCalculator {
static int getRate(double discount) {
if (discount < 100) {
String discounted = discount.toStringAsFixed(1);
String first = discounted.substring(0, discounted.indexOf("."));
String last = discounted.substring(discounted.indexOf(".") + 1);
int firstNumber = int.parse(first);
int lastNumber = int.parse(last);
if (discount < 0.51) {
return 0;
} else if (discount < 2) {
return 1;
} else if (firstNumber < lastNumber) {
return lastNumber;
} else if (firstNumber > lastNumber) {
return firstNumber;
} else {
return firstNumber;
}
} else if (discount < 1000) {
double result = discount % 100;
if (result == 0) {
return 100;
} else {
return result.ceil();
}
} else {
return 100;
}
}
}