Loan Amortization returns only the last item java -
this question has answer here:
i stuck loan amortization list gives me last item multiple times. method:
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 q , go step 1: thusly loop around until value q (and hence p) goes zero. balance = curbalance; } return lineitems; }
my web service method:
@webresult(name = "paymentplan") @webmethod(operationname = "getloanpaymentplan") public list<amortizationschedulelineitem> getloanpaymentplan() { amortizationscheduleinput input = new amortizationscheduleconsoleinputoutput().readuserinputfromconsole(); loanamortizationschedule loan = new loanamortizationschedule(input); return loan.calculateamortizationschedule(); }
my response:
<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>
what do other items in list?
you need create new item object in each iteration of loop
while (....) { amortizationschedulelineitem item = new amortizationschedulelineitem(); ... listitems.add (item); }
otherwise working on same object time
Comments
Post a Comment