Skip to content

Instantly share code, notes, and snippets.

@jderda
Created October 30, 2016 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jderda/2f451db734e8cfacaaa12c1094b8e3b1 to your computer and use it in GitHub Desktop.
Save jderda/2f451db734e8cfacaaa12c1094b8e3b1 to your computer and use it in GitHub Desktop.
Rozwiązanie zadania z #main z 24 października 2016
public class CoffeePriceCalculator {
public double getFinalPrice(double cofeePrice, int taxPercents, int tipPercents) {
long roundedAmountInGrosze = Math.round(cofeePrice*(100 + taxPercents + tipPercents));
return roundedAmountInGrosze/100.0;
}
}
import java.math.BigDecimal;
import java.math.RoundingMode;
public class CofeePriceCalculator {
public BigDecimal getFinalPrice(BigDecimal cofeePrice, int taxPercents, int tipPercents) {
BigDecimal amountInGrosze = cofeePrice.multiply(BigDecimal.valueOf(100 + taxPercents + tipPercents));
BigDecimal result = amountInGrosze.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment