switch (cmdletter) {
case 'b': // balance
System.out.println("Current balance is " + account);
break;
case 'd': // deposit
case 'w': // withdrawal
amountAsDouble = RitIo.getDouble("Amount: ");
amountAsInt = (int) amountAsDouble;
amountAsDouble -= amountAsInt; // 123.456 becomes 0.456
amountAsInt *= 100; // take int part as dollars (12300)
amountAsDouble *= 100; // becomes 45.6
amountAsInt += (int) amountAsDouble; // becomes 12345
if (cmdletter == 'd') {
account.deposit(amountAsInt);
} else {
account.withdraw(amountAsInt);
}
break;
|