Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have to modify this program with an outer for loop to do 4%, 6%, 8%, 10% inter

ID: 3542710 • Letter: I

Question

I have to modify this program with an outer for loop to do 4%, 6%, 8%, 10% interest. rates and print the results for each of the interest rates. Here is the original program.



public class Interest {
    
       public static void main( String args[] )
       {
          double amount;        // amount on deposit at end of each year
          double prin = 1000.0;   // initial amount before interest
          double rate = 0.04;   // interest rate

          System.out.printf( "%s%20s ", "Year", "Amount on deposit" );
           // calculate amount on deposit for each of ten years
       
          for ( int year = 1; year <= 10; year++ ) {
              // calculate new amount for specified year
             amount = prin * Math.pow( 1.0 + rate, year );
              // display year and amount
             System.out.printf( "%4d%,20.2f ", year, amount );
          } // endfor
       } // end main()
    } // end class Interest



Explanation / Answer

This shows Rates as well :


public class Interest {


public static void main( String args[] )

{

double amount; // amount on deposit at end of each year

double prin = 1000.0; // initial amount before interest

double rate = 0.04; // interest rate


for(int i=0;i<4;i++)

{

System.out.println(" Rate is : "+rate*100 +"%");

System.out.printf( "%s%20s ", "Year", "Amount on deposit" );

// calculate amount on deposit for each of ten years


for ( int year = 1; year <= 10; year++ ) {

// calculate new amount for specified year

amount = prin * Math.pow( 1.0 + rate, year );

// display year and amount

System.out.printf( "%4d%,20.2f ", year, amount );

} // endfor

rate+=0.02;

}//end outer for

} // end main()

} // end class Interest