import java.math.BigDecimal;
import java.math.RoundingMode;
class Calculo {
private static final int PRECISAO_CALCULO = 21;
private static final int PRECISAO_FINAL = 5;
a,
PRECISAO_CALCULO,
RoundingMode.HALF_EVEN);
.subtract(b)
.multiply(p)
.divide(j, PRECISAO_CALCULO, RoundingMode.HALF_EVEN);
}
private static final BigDecimal taxaFinanciamento
( int n,
{
if (m1.abs().compareTo(DELTA) <= 0) return j1;
if (m2.abs().compareTo(DELTA) <= 0) return j2;
for (int i = 0; i < 50; i++) {
if (m1.signum() == m2.signum()) {
+ ": q1=[" + q1 + "], j1=[" + j1 + "], m1=[" + m1 + "]"
+ ", q2=[" + q2 + "], j2=[" + j2 + "], m2=[" + m2 + "]"
+ ", i=" + i);
}
if (m3.abs().compareTo(DELTA) <= 0) return j3;
if (m3.signum() == m1.signum()) {
q1 = q3;
j1 = j3;
} else {
q2 = q3;
j2 = j3;
}
}
+ ": q1=[" + q1 + "], j1=[" + j1 + "], m1=[" + m1 + "]"
+ ", q2=[" + q2 + "], j2=[" + j2 + "], m2=[" + m2 + "]");
}
private static void teste(int q0, int p, int n) {
BigDecimal j
= taxaFinanciamento
(bdq0Ideal, n, bdp
); System.
out.
println("----------"); System.
out.
println("q0-ideal=[" + bdq0Ideal
+ "]"); System.
out.
println("p=[" + bdp
+ "]"); System.
out.
println("j=[" + j
+ "]"); System.
out.
println("q0-obtido=[" + bdq0Obtido
+ "]"); System.
out.
println("----------"); }
public static void main
(String[] args
) { teste(750, 86, 10);
teste(750, 85, 10);
}
}
aW1wb3J0IGphdmEubWF0aC5CaWdEZWNpbWFsOwppbXBvcnQgamF2YS5tYXRoLlJvdW5kaW5nTW9kZTsKCmNsYXNzIENhbGN1bG8gewoKICAgIHByaXZhdGUgc3RhdGljIGZpbmFsIEJpZ0RlY2ltYWwgQ0VNID0gbmV3IEJpZ0RlY2ltYWwoMTAwKTsKICAgIHByaXZhdGUgc3RhdGljIGZpbmFsIEJpZ0RlY2ltYWwgRE9JUyA9IG5ldyBCa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VEE7CiAgICAgICAgQmlnRGVjaW1hbCBqMiA9IEJpZ0RlY2ltYWwuT05FOwogICAgICAgIEJpZ0RlY2ltYWwgcTEgPSBmaW5hbmNpYW1lbnRvKG4sIGoxLCBwKTsKICAgICAgICBCaWdEZWNpbWFsIHEyID0gZmluYW5jaWFtZW50byhuLCBqMiwgcCk7CiAgICAgICAgQmlnRGVjaW1hbCBtMSA9IHExLnN1YnRyYWN0KHEwKTsKICAgICAgICBCaWdEZWNpbWFsIG0yID0gcTIuc3VidHJhY3QocTApOwogICAgICAgIGlmIChtMS5hYnMoKS5jb21wYXJlVG8oREVMVEEpIDw9IDApIHJldHVybiBqMTsKICAgICAgICBpZiAobTIuYWJzKCkuY29tcGFyZVRvKERFTFRBKSA8PSAwKSByZXR1cm4gajI7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCA1MDsgaSsrKSB7CiAgICAgICAgICAgIGlmIChtMS5zaWdudW0oKSA9PSBtMi5zaWdudW0oKSkgewogICAgICAgICAgICAgICAgdGhyb3cgbmV3IEFyaXRobWV0aWNFeGNlcHRpb24oIkZvcmEgZG8gaW50ZXJ2YWxvIgogICAgICAgICAgICAgICAgICAgICAgICArICI6IHExPVsiICsgcTEgKyAiXSwgajE9WyIgKyBqMSArICJdLCBtMT1bIiArIG0xICsgIl0iCiAgICAgICAgICAgICAgICAgICAgICAgICsgIiwgcTI9WyIgKyBxMiArICJdLCBqMj1bIiArIGoyICsgIl0sIG0yPVsiICsgbTIgKyAiXSIKICAgICAgICAgICAgICAgICAgICAgICAgKyAiLCBpPSIgKyBpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBCaWdEZWNpbWFsIGozID0gajEuYWRkKGoyKS5kaXZpZGUoRE9JUyk7CiAgICAgICAgICAgIEJpZ0RlY2ltYWwgcTMgPSBmaW5hbmNpYW1lbnRvKG4sIGozLCBwKTsKICAgICAgICAgICAgQmlnRGVjaW1hbCBtMyA9IHEzLnN1YnRyYWN0KHEwKTsKICAgICAgICAgICAgaWYgKG0zLmFicygpLmNvbXBhcmVUbyhERUxUQSkgPD0gMCkgcmV0dXJuIGozOwogICAgICAgICAgICBpZiAobTMuc2lnbnVtKCkgPT0gbTEuc2lnbnVtKCkpIHsKICAgICAgICAgICAgICAgIHExID0gcTM7CiAgICAgICAgICAgICAgICBqMSA9IGozOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcTIgPSBxMzsKICAgICAgICAgICAgICAgIGoyID0gajM7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhyb3cgbmV3IEFyaXRobWV0aWNFeGNlcHRpb24oIk7Do28gY29udmVyZ2l1IgogICAgICAgICAgICAgICAgKyAiOiBxMT1bIiArIHExICsgIl0sIGoxPVsiICsgajEgKyAiXSwgbTE9WyIgKyBtMSArICJdIgogICAgICAgICAgICAgICAgKyAiLCBxMj1bIiArIHEyICsgIl0sIGoyPVsiICsgajIgKyAiXSwgbTI9WyIgKyBtMiArICJdIik7CiAgICB9CgogICAgcHJpdmF0ZSBzdGF0aWMgdm9pZCB0ZXN0ZShpbnQgcTAsIGludCBwLCBpbnQgbikgewogICAgICAgIEJpZ0RlY2ltYWwgYmRxMElkZWFsID0gbmV3IEJpZ0RlY2ltYWwocTApOwogICAgICAgIEJpZ0RlY2ltYWwgYmRwID0gbmV3IEJpZ0RlY2ltYWwocCk7CiAgICAgICAgQmlnRGVjaW1hbCBqID0gdGF4YUZpbmFuY2lhbWVudG8oYmRxMElkZWFsLCBuLCBiZHApOwogICAgICAgIEJpZ0RlY2ltYWwgYmRxME9idGlkbyA9IGZpbmFuY2lhbWVudG8obiwgaiwgYmRwKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIi0tLS0tLS0tLS0iKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oInEwLWlkZWFsPVsiICsgYmRxMElkZWFsICsgIl0iKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oInA9WyIgKyBiZHAgKyAiXSIpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiaj1bIiArIGogKyAiXSIpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigicTAtb2J0aWRvPVsiICsgYmRxME9idGlkbyArICJdIik7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCItLS0tLS0tLS0tIik7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgICB9CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIHRlc3RlKDc1MCwgODYsIDEwKTsKICAgICAgICB0ZXN0ZSg3NTAsIDg1LCAxMCk7CiAgICB9Cn0=