Results 1 to 3 of 3
  1. #1
    javadog is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

  3. #3
    javadog is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default 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

  1. Array , Loop ?
    By HearT.Hunt3r in forum New To Java
    Replies: 3
    Last Post: 08-16-2011, 11:41 AM
  2. Array or for loop? or both?
    By kedecr in forum New To Java
    Replies: 4
    Last Post: 03-09-2011, 01:24 PM
  3. Loop through Array in JSP
    By Robert_85 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-25-2010, 09:00 PM
  4. Simple Programming problem loop in array
    By katon in forum New To Java
    Replies: 1
    Last Post: 12-20-2009, 03:14 PM
  5. Replies: 2
    Last Post: 05-05-2008, 01:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •