Results 1 to 3 of 3
Thread: Array and Loop Problem
- 09-04-2011, 10:56 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
Array and Loop Problem
Can somebodu PLEASE help me get this program to scroll through each individual term ending with a balance with 0.00 for each. Please help!!
Java Code:public class Monthly_Array { public static void main(String[] args) { double loanAmount=200000.00; double[] rate = {.0535, .055, .0575}; int[] term = {84, 180, 360}; double balance = loanAmount; double monthlyInterest = 0; double monthlyPrincipal = 0; double monthlyPayment = 0; int i; for (i = 0; i < term.length; i++){ monthlyPayment = (loanAmount * (rate[i]/12))/(1-1/Math.pow((1 + rate[i]/12),(term[i]))); monthlyInterest = balance * (rate[i]/12); monthlyPrincipal = monthlyPayment - monthlyInterest; balance -= monthlyPrincipal; System.out.print("Term: " + term[i] + " Months:" ); System.out.print(" The Monthly Payment is: "); System.out.printf( "%,.2f" , monthlyPayment ); System.out.print(" The Interest Rate is: "); System.out.printf( "%,.2f", monthlyInterest ); System.out.print(" The Principal is: "); System.out.printf( "%,.2f", monthlyPrincipal ); System.out.print(" The Balance is: "); System.out.printf( "%,.2f", balance ); System.out.println(); } } }
- 09-04-2011, 11:56 AM #2
Re: Array and Loop Problem
- 09-04-2011, 12:38 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
Re: Array and Loop Problem
Thanks for your help but unfortunately that does not solve my problem and I accidently posted the wrong code it scrolls to the end, which is 360 but at the end of 84, 180, and 360 the balance should be 0.00 and reset for the next term, but that is not happening and I cant figure out the problem. Please Help anything will be Appreciated!!
Java Code:import java.util.Scanner; public class Amortization_Array2 { /** * @param args */ public static void main(String[] args) { double a = 200000.00; double[] i = {0.0535, 0.055, 0.0575}; int[] n = {84, 180, 360}; i = new double [3]; n = new int [3]; i[0] = 0.0535; n[0] = 84; i[1] = 0.055; n[1] = 180; i[2] = 0.0575; n[2] = 360; Scanner keyboard = new Scanner (System.in); double r = (1+i[0]/12); double monthlyPayments = a * ( r - 1 ) / ( 1 - Math.pow(r,-n[0])); int cnt = 0; for ( cnt = 0; cnt <= 84; cnt++) { double interest = a * ( i[0]/12 ); r = (1+i[0]/12); double principal = monthlyPayments - interest ; double balance = a - principal; a = balance; System.out.println(" Payment Number: " + cnt); System.out.print("The monthly Payment Amount is: " ); System.out.printf( "%,.2f" , monthlyPayments ); System.out.print(" The Interest is: " ); System.out.printf( "%,.2f", interest ); System.out.print(" The Principal Payment is: "); System.out.printf( "%,.2f", principal ); System.out.print(" The Balance is: "); System.out.printf( "%,.2f", balance ); if (cnt % 24 == 0) { System.out.println(); System.out.println(" Press Enter To Continue..."); keyboard.nextLine(); r = (1+i[1]/12); monthlyPayments = a * ( r - 1 ) / ( 1 - Math.pow(r,-n[1])); for ( cnt = 0; cnt <= 180; cnt++) { interest = a * ( i[1]/12 ); principal = monthlyPayments - interest ; balance = a - principal; a = balance; System.out.println(" Payment Number: " + cnt); System.out.print("The monthly Payment Amount is: " ); System.out.printf( "%,.2f" , monthlyPayments ); System.out.print(" The Interest is: " ); System.out.printf( "%,.2f", interest ); System.out.print(" The Principal Payment is: "); System.out.printf( "%,.2f", principal ); System.out.print(" The Balance is: "); System.out.printf( "%,.2f", balance ); if (cnt % 24 == 0) { System.out.println(); System.out.println(" Press Enter To Continue..."); keyboard.nextLine(); r = (1+i[2]/12); monthlyPayments = a * ( r - 1 ) / ( 1 - Math.pow(r,-n[2])); for ( cnt = 0; cnt <= 360; cnt++) { interest = a * ( i[2]/12 ); principal = monthlyPayments - interest ; balance = a - principal; a = balance; System.out.println(" Payment Number: " + cnt); System.out.print("The monthly Payment Amount is: " ); System.out.printf( "%,.2f" , monthlyPayments ); System.out.print(" The Interest is: " ); System.out.printf( "%,.2f", interest ); System.out.print(" The Principal Payment is: "); System.out.printf( "%,.2f", principal ); System.out.print(" The Balance is: "); System.out.printf( "%,.2f", balance ); if (cnt % 24 == 0) { System.out.println(); System.out.println(" Press Enter To Continue..."); keyboard.nextLine(); } } } } } } } }
Similar Threads
-
Array , Loop ?
By HearT.Hunt3r in forum New To JavaReplies: 3Last Post: 08-16-2011, 11:41 AM -
Array or for loop? or both?
By kedecr in forum New To JavaReplies: 4Last Post: 03-09-2011, 01:24 PM -
Loop through Array in JSP
By Robert_85 in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 04-25-2010, 09:00 PM -
Simple Programming problem loop in array
By katon in forum New To JavaReplies: 1Last Post: 12-20-2009, 03:14 PM -
Need another program with and if-else, array, and for loop
By Zebra in forum New To JavaReplies: 2Last Post: 05-05-2008, 01:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks