public class Bank
{    double goal = 10000;
    double interestRate = 0.05;
    double balance = 2000;
    int year = 0;

public void nestedLoop()
{     String r = "";
    for (int row = 1; row < 8; row++)
    { // make a row of the triangle:
        for (int col = 0; col < row; col++)
        {     r = r + "[]" ;
        }
    r = r + "\n";
    }
JOptionPane.showMessageDialog(null, r);
}

public void reachTarget()
{ while(balance < goal)
{    //balance = balance + balance * interestRate;
    // OR
    balance += balance * interestRate;
    year++;
}
String msg = "After " + year + " years, ";
msg += "the balance is $" + balance;
JOptionPane.showMessageDialog(null, msg);
}

public void reachTarget2()
{ // use a FOR loop
int i;
String msg = "How many years? ";
String yearsStr = JOptionPane.showInputDialog(msg);
int years = Integer.parseInt(yearsStr);
for (i = 0; i < years; i++)
{    System.out.println(i + " " + balance);
    balance += balance * interestRate;
}
msg = "Balance after " + years + " years is $";
msg += balance;
JOptionPane.showMessageDialog(null, msg);
}

public void tryThis()
{ String xStr = JOptionPane.showInputDialog("Positive Number? ");
double x = Double.parseDouble(xStr);
int result1 = (int)(x + 0.5);
int result2 = (int)Math.round(x);
String msg = "Two results: " + result1 + " " + result2;
JOptionPane.showMessageDialog(null, msg);
}

public static void main(String[] args)
{ Bank bank = new Bank();
bank.nestedLoop();
}
}