贷款摊销 returns 只有最后一项 java
Loan Amortization returns only the last item java
我被一个贷款摊销清单困住了,它多次只给我最后一项。我的方法:
public List<AmortizationScheduleLineItem> calculateAmortizationSchedule() {
List<AmortizationScheduleLineItem> lineItems = new ArrayList<AmortizationScheduleLineItem>();
AmortizationScheduleLineItem item = new AmortizationScheduleLineItem();
long balance = amountBorrowed;
int paymentNumber = 0;
long totalPayments = 0;
long totalInterestPaid = 0;
item.setPaymentNumber(paymentNumber++);
item.setPaymentAmount(0d);
item.setPaymentInterest(0d);
item.setCurrentBalance(((double) amountBorrowed) / 100d);
item.setTotalPayments(((double) totalPayments) / 100d);
item.setTotalInterestPaid(((double) totalInterestPaid) / 100d);
lineItems.add(item);
final int maxNumberOfPayments = initialTermMonths + 1;
while ((balance > 0) && (paymentNumber <= maxNumberOfPayments)) {
long curMonthlyInterest = Math.round(((double) balance) * monthlyInterest);
long curPayoffAmount = balance + curMonthlyInterest;
long curMonthlyPaymentAmount = Math.min(monthlyPaymentAmount, curPayoffAmount);
if ((paymentNumber == maxNumberOfPayments)
&& ((curMonthlyPaymentAmount == 0) || (curMonthlyPaymentAmount == curMonthlyInterest))) {
curMonthlyPaymentAmount = curPayoffAmount;
}
long curMonthlyPrincipalPaid = curMonthlyPaymentAmount - curMonthlyInterest;
long curBalance = balance - curMonthlyPrincipalPaid;
totalPayments += curMonthlyPaymentAmount;
totalInterestPaid += curMonthlyInterest;
item.setPaymentNumber(paymentNumber++);
item.setPaymentAmount(((double) curMonthlyPaymentAmount) / 100d);
item.setPaymentInterest(((double) curMonthlyInterest) / 100d);
item.setCurrentBalance(((double) curBalance) / 100d);
item.setTotalPayments(((double) totalPayments) / 100d);
item.setTotalInterestPaid(((double) totalInterestPaid) / 100d);
lineItems.add(item);
// Set P equal to Q and go back to Step 1: You thusly loop around until the value Q (and hence P) goes to zero.
balance = curBalance;
}
return lineItems;
}
我的 Web 服务方法:
@WebResult(name = "PaymentPlan")
@WebMethod(operationName = "GetLoanPaymentPlan")
public List<AmortizationScheduleLineItem> GetLoanPaymentPlan() {
AmortizationScheduleInput input = new AmortizationScheduleConsoleInputOutput().readUserInputFromConsole();
LoanAmortizationSchedule loan = new LoanAmortizationSchedule(input);
return loan.calculateAmortizationSchedule();
}
我的回复:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:GetLoanPaymentPlanResponse xmlns:ns2="http://service.dfcu.com/">
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
</ns2:GetLoanPaymentPlanResponse>
</S:Body>
</S:Envelope>
如何获取列表中的其他项目?
您需要在循环的每次迭代中创建一个新的项目对象
while (....)
{
AmortizationScheduleLineItem item = new AmortizationScheduleLineItem();
...
listItems.add (item);
}
否则你一直在处理同一个对象
我被一个贷款摊销清单困住了,它多次只给我最后一项。我的方法:
public List<AmortizationScheduleLineItem> calculateAmortizationSchedule() {
List<AmortizationScheduleLineItem> lineItems = new ArrayList<AmortizationScheduleLineItem>();
AmortizationScheduleLineItem item = new AmortizationScheduleLineItem();
long balance = amountBorrowed;
int paymentNumber = 0;
long totalPayments = 0;
long totalInterestPaid = 0;
item.setPaymentNumber(paymentNumber++);
item.setPaymentAmount(0d);
item.setPaymentInterest(0d);
item.setCurrentBalance(((double) amountBorrowed) / 100d);
item.setTotalPayments(((double) totalPayments) / 100d);
item.setTotalInterestPaid(((double) totalInterestPaid) / 100d);
lineItems.add(item);
final int maxNumberOfPayments = initialTermMonths + 1;
while ((balance > 0) && (paymentNumber <= maxNumberOfPayments)) {
long curMonthlyInterest = Math.round(((double) balance) * monthlyInterest);
long curPayoffAmount = balance + curMonthlyInterest;
long curMonthlyPaymentAmount = Math.min(monthlyPaymentAmount, curPayoffAmount);
if ((paymentNumber == maxNumberOfPayments)
&& ((curMonthlyPaymentAmount == 0) || (curMonthlyPaymentAmount == curMonthlyInterest))) {
curMonthlyPaymentAmount = curPayoffAmount;
}
long curMonthlyPrincipalPaid = curMonthlyPaymentAmount - curMonthlyInterest;
long curBalance = balance - curMonthlyPrincipalPaid;
totalPayments += curMonthlyPaymentAmount;
totalInterestPaid += curMonthlyInterest;
item.setPaymentNumber(paymentNumber++);
item.setPaymentAmount(((double) curMonthlyPaymentAmount) / 100d);
item.setPaymentInterest(((double) curMonthlyInterest) / 100d);
item.setCurrentBalance(((double) curBalance) / 100d);
item.setTotalPayments(((double) totalPayments) / 100d);
item.setTotalInterestPaid(((double) totalInterestPaid) / 100d);
lineItems.add(item);
// Set P equal to Q and go back to Step 1: You thusly loop around until the value Q (and hence P) goes to zero.
balance = curBalance;
}
return lineItems;
}
我的 Web 服务方法:
@WebResult(name = "PaymentPlan")
@WebMethod(operationName = "GetLoanPaymentPlan")
public List<AmortizationScheduleLineItem> GetLoanPaymentPlan() {
AmortizationScheduleInput input = new AmortizationScheduleConsoleInputOutput().readUserInputFromConsole();
LoanAmortizationSchedule loan = new LoanAmortizationSchedule(input);
return loan.calculateAmortizationSchedule();
}
我的回复:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:GetLoanPaymentPlanResponse xmlns:ns2="http://service.dfcu.com/">
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
<PaymentPlan>
<currentBalance>0.0</currentBalance>
<paymentAmount>0.05</paymentAmount>
<paymentInterest>0.0</paymentInterest>
<paymentNumber>61</paymentNumber>
<totalInterestPaid>396095.05</totalInterestPaid>
<totalPayments>1396095.05</totalPayments>
</PaymentPlan>
</ns2:GetLoanPaymentPlanResponse>
</S:Body>
</S:Envelope>
如何获取列表中的其他项目?
您需要在循环的每次迭代中创建一个新的项目对象
while (....)
{
AmortizationScheduleLineItem item = new AmortizationScheduleLineItem();
...
listItems.add (item);
}
否则你一直在处理同一个对象