Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Need help with Math.pow Calculations

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 02-12-2012, 10:38 PM PM User | #1 KenanCross New to the CF scene   Join Date: Feb 2012 Posts: 3 Thanks: 2 Thanked 0 Times in 0 Posts Need help with Math.pow Calculations Hello again! Thanks for the help in the previous post I made last week. I'm in need of a little bit of assistance again. I'm trying to get Math.pow to calculate and produce a result for my Mortgage Calculator project. I need to show a decreasing amount in the remaining balance of a mortgage loan. However the results I get seem to always stay the same. What am I doing wrong? Code: ```import java.text.DecimalFormat; // This calculator will accurately calculate Mortgage Payments, while allowing for flexible variable adjustments //(i.e. Length of Payments, Principal, Interest.) Based on Service Request from McBride Financial // Author: Kenan Cross // public class MortgageCalculator { int i; // counter int termLimit = 30; int months; int payments; /* No. of monthly payments in mortgage*/ int monthsPd = 12 * i; //Calculations of months paid so far double balPd; //Part of Balance Paid Formula double balPd2; //Part of Balance Paid Formula double balPd3; //Part of Balance Paid formula double balPdCalc; //Calculated result of balPd and balPd2 double loanCalc; //Power of Calculation for compound interest double powCalc; //Power of calculation variable double rate; double loanBalance; double loanInterest; //Calculated Loan with Interest double newLoanBalance; //Calculated Remaining Loan Balanace double annualRate; //Computed Annual Rate double interestPlus; // rate + 1 double interestPd; // contains interest paid so far double interestAdj; double interestExp; int length; /* length of mortgage */ double principle; /* Principle loan amount */ double monthlyPayment; /* Calculated Monthly Payment */ DecimalFormat dec; DecimalFormat percentage; public static void main (String args[]){ MortgageCalculator calc = new MortgageCalculator(); calc.calculatePaymentAmount(); calc.printPaymentAmount(); } public MortgageCalculator(){ months = 12; rate = 0.0575; principle = 200000; length = 30; dec = new DecimalFormat ("\$0.00"); percentage = new DecimalFormat("0.00%"); } public void calculatePaymentAmount(){ annualRate = ((rate)/(12)); payments = (months) * (length); interestAdj = (annualRate)+(1); interestPlus = (rate + 1); interestExp = Math.pow(interestAdj, payments); monthlyPayment = principle * (annualRate * interestExp)/(interestExp - 1); loanCalc = principle * (Math.pow(interestAdj,(termLimit))); } //Above formula is based on M=P[i(1+i)^n]/[(1+i)^n-1] found on ifitbreaks.com/interest.htm// public void printPaymentAmount (){ System.out.println("Your Loan Amount is "+ dec.format(principle)); System.out.println("Your Annual Rate is "+ percentage.format(rate)); System.out.println("Your monthly payment amount is " + dec.format (monthlyPayment)); System.out.println("Your principal balance with interest is " + dec.format (loanCalc)); for (i=1; i <= termLimit; i++){ //Loop set for the limit of Mortgage term powCalc = principle * (Math.pow(interestAdj, i))-1; balPd = monthlyPayment/annualRate; balPd2 = balPd - principle; balPd3 = 1 - Math.pow(annualRate, monthsPd); balPdCalc = balPd - (balPd2 * balPd3); //formula is based on Amt Paid = (L/R - P)[(1+R)^X - 1] found // at http://www.infobarrel.com/Financial_Math:__Calculating_the_Mortgage_Balance_after_X_Number_of_Years interestPd = powCalc - principle; System.out.println("\tIn Year " + i + " you will have paid " + dec.format(interestPd) + " in interest."); System.out.println("\t Your remaining loan balance is " + dec.format(balPdCalc)); try { Thread.sleep(5000); } catch (InterruptedException e) { } } } }```
 02-15-2012, 07:18 PM PM User | #2 clinto New to the CF scene   Join Date: Feb 2012 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts One thing that is happening is your monthsPd variable is being initialized at 12 * i; and never changes through each iteration. You want to move it into your for loop. Code: ``` for (i=1; i <= termLimit; i++){ //Loop set for the limit of Mortgage term monthsPd = 12 * i;``` Based on the formulas I see on http://www.infobarrel.com/Financial_...umber_of_Years I came up with this code: Code: ``` double amtPaid = (monthlyPayment/annualRate - principle) * (Math.pow(1 + annualRate, monthsPd) - 1); double mortgageBalance = loanCalc - amtPaid;``` You would then print mortgageBalance. Code: `System.out.println("\t Your remaining loan balance is " + dec.format(mortgageBalance));`

 Bookmarks

 Tags java, math.pow

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 11:03 PM.