Link to home
Start Free TrialLog in
Avatar of javahound
javahound

asked on

Java Amortization Array

Can somebody PLEASE Help me with this problem!! Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%

Use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen.
I am trying to get my code to scroll through each term with an ending balance of 0.00 and then reset to the initial balance for each term but it continues through 360 with the same monthly payment amount and none of the other numbers seem correct either. any help will be greatly appreciated.

import java.util.Scanner;
 
public class Amortization_Array2 {

	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();




					}
			}
	  }
}  
}
}
}
}

		   
	

Open in new window

Avatar of webdev2000
webdev2000

Avatar of javahound

ASKER

Thanks But that does not solve my problem, I am lost and dont know where to make my next move Please Help!!
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
as this is academic assignement, according to EE rules we are not supposed to provide the final working code
for you - so try to complete it yourself - let us know if you
have any questions.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How do I get the monthly payment amount to stay constant but different for each term and how do i get the balance to end at 0.00 at the end of each term. Please help
Look at my last code  - you add one more varuiable - ay, "initial" like in my code
and you assign value of initial to "a" at the beginning of each of three tasks -
then you vlaue of "a" will change,
but initial will stay the same
and begore next case (for 15 years and 30 years) you again assign value of "initial" to "a"
se my last version of the program

In Java all arrays, loops etc, begin with zero
Therefore if you need to pay say  84  times you should end your loop when
your lopp variable is not 84, but is less than 84,
so yoour loops should not end iin cnt<=84
the should end when cnt < 84

when cnt = 84 - that will already be 85th payment as you start with zero

check and correct ot in your code
I did that and an error tells me that it cannot be resolved to a variable, what does that mean

"I did that" - what you did ?
There shuild not be any error as it works for me - I don't want to post  the very final code as you shoukd do the final steps yourself  as it is your hometask. But the last code I posted is really very close. Just read my remark about how you should end the loops in java
The problem that the variable initial cannot be resolved to a variable has not changed and I have no idea what that means or how to fix it so could you please give me some help
Use my last code - it does not give any error
First take my last code exactly as it is - just cut and paste - it cannot give any error as it compiles and runs for me
I think I got it but for the second term the interest starts out at 0.00 and the balance starts at
 -2,859.79 please give me some support on this because it does not make sense
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No I am not getting the errors anymore but the second term the interest starts out at 0.00 and the balance starts at -2,859.79 and several of the other ending numbers are negative or incorrect please give me some support on this because it does not make sense
Post you code.

Whay are you not using my last code?
that worked for all the lines except 180 and 360 which end with -0.00 how do i fix that
What you want to fix if they end with zero ?
Yes I am using your code and I changed the loops but as I said on line 180 and 360 the balance ends with -0.00
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am very new to java but I feel like i should have known how to fix the problem. But anyway Thank You  so much that fixed everything!!
-0.00 is the same thing as 0.00 so there is no reason to worry abouut it
Thank You For your help tou really helped me. THANK YOU!!