#### Calculating simple interest rates on an initial cash investment

Again, someone out there may have seen this as homework somewhere. And again, the solution might not be perfect, but it should be close enough.
Java Code:
```/**
* This will take an initial amount of capital and work out
* the return for each year that capital is left in the
* account assuming a simple interest rate and that it
* is left sitting in the account accumulating the rate
* defined near the top of the source code. There might
* be some refinement needed here.
*
* @author Shaun B
* @version 2012-10-30
*/
import java.util.Scanner;
public class exerciseThree
{
// Here is our fixed interest rate expressed as a final (ie, cannot be modified):
private static final double fixedInterestRate = (double)2.3;
private static int numberOfYears = 0;
private static Scanner keyboardInput = new Scanner(System.in);
private static boolean run = true;
public static void main(String [] elephants)
{
// Local variables available in this scope only:
int i = 0;
double total = 0.00;
double capital = 0.00;
int step = 0;
double currentBalance = 0.00;
String keyboardError="Illegal keyboard entry in main class";
// User instructions:
System.out.format("The current fixed interest rate is at %f\n",fixedInterestRate);
System.out.println("the interest after each year up to 500 years. You will be");
System.out.println("of interest and the step in each year(ie, 5 will show you");
System.out.println("how much interest is added after each five years up to the");
System.out.println("maximum that you enter).");
while (run)
{
System.out.print("How much capital do you wish to invest? £");
try
{
capital = keyboardInput.nextDouble();
}
catch(Exception e)
{
System.err.println(keyboardError);
run = false;
System.exit(0);
}
System.out.print("How many years do you wish to calculate the interest? ");
try
{
numberOfYears = keyboardInput.nextInt();
}
catch(Exception e)
{
System.err.println(keyboardError);
run = false;
System.exit(0);
}
System.out.print("How often do you wish to see the balance (ie, every 5 years)? ");
try
{
step = keyboardInput.nextInt();
}
catch(Exception e)
{
System.err.println(keyboardError);
run = false;
System.exit(0);
}
if (capital == 0 || numberOfYears == 0 || step == 0)
{
System.out.println("Goodbye!");
run = false;
System.exit(0);
}
for( i=1; i<=numberOfYears; ++i )
{
// The exercise seems to be asking for a simple interest calculation,
// rather than a compound interest calculation, and this is the formula
// provided on the sheet, so it seems to be okay. I'd check this - search
// online for a simple interest calculator in Java or C/C++ and you
// should have a more perfect solution I think.
currentBalance = (double)capital*(1.00f + 0.01f * fixedInterestRate);
if(i%step==0 && i!=0)
{
// Prints out the current balance to two decimal places:
System.out.format("After %d years, the balance is %.2f", i, currentBalance);
System.out.println("");
}
capital = (double)currentBalance;
}
}
}
}```

Cheers,

Shaun.