public void runningBalance(MainWindow mw) {
InputBox in = new InputBox(mw);
OutputBox out = new OutputBox(mw);
int balance = in.getInteger("Enter the initial balance:");
out.show();
String ans;
int amount;
boolean again = true;
do {
ans = in.getString("Deposit (d), withdraw (w), or quit (q)?");
switch (ans.charAt(0)) {
case 'd':
case 'D':
amount = in.getInteger("How much do you want to deposit?");
if (amount < 0)
out.printLine("Cannot deposit negative amount");
else {
balance += amount;
out.printLine("Current balance: " + balance);
}
break;
case 'w':
case 'W':
amount = in.getInteger("How much do you want to withdraw?");
if (amount < 0)
out.printLine("Cannot withdraw negative amount");
else {
balance -= amount;
out.printLine("Current balance: " + balance);
}
break;
case 'q':
case 'Q':
out.printLine("Final balance: " + balance);
again = false;
default:
out.printLine("Please enter d, w, or q");
} // end switch
} while (again);
} // end method runningBalance