Hey, I am currently taking a java course at school and i have to write a program that acts like an atm. I finally got my "do while" loop to work, but now it is doing some freaky arithmetic. Just wondering if anyone can help me in figuring out what kind of math is going on here...
CODE:
public class MiniTeller
{
public static void main(String[] arg)
{
TextReader keyboard = new TextReader();
BankAccount currentAccount = new BankAccount("Jackson", 100.00);
System.out.println("Initial Balance for Jackson is " + currentAccount.getBalance());
String hmm;
do
{
System.out.print("W)ithdraw, D)eposit, B)alance, or Q)uit: ");
String whatToDo = keyboard.readLine();
hmm = whatToDo;
if(whatToDo.equalsIgnoreCase("w"))
{
System.out.print("Enter withdrawal amount: ");
double withdraw = keyboard.readDouble();
currentAccount.withdraw(withdraw);
//System.out.println();
if(withdraw > currentAccount.getBalance())
System.out.println("Insufficient Funds...");
}
else
{
if(whatToDo.equalsIgnoreCase("d"))
{
System.out.print("Enter deposit amount: ");
double deposit = keyboard.readDouble();
currentAccount.deposit(deposit);
//System.out.println();
}
else
{
if(whatToDo.equalsIgnoreCase("b"))
{
System.out.println("Current Balance: " + currentAccount.getBalance());
// System.out.println();
}
else
{
if(whatToDo.equalsIgnoreCase("q"))
System.out.println("Have a nice whatever : )");
}
}
}
}
while(!(hmm.equalsIgnoreCase("q")));
}
}
OUTPUT:
--------------------Configuration: --------------------
Initial Balance for Jackson is 100.0
W)ithdraw, D)eposit, B)alance, or Q)uit: b
Current Balance: 100.0
W)ithdraw, D)eposit, B)alance, or Q)uit: w
Enter withdrawal amount: 98.91
Insufficient Funds...
W)ithdraw, D)eposit, B)alance, or Q)uit: b
Current Balance: 1.0900000000000034
W)ithdraw, D)eposit, B)alance, or Q)uit:
CODE:
public class MiniTeller
{
public static void main(String[] arg)
{
TextReader keyboard = new TextReader();
BankAccount currentAccount = new BankAccount("Jackson", 100.00);
System.out.println("Initial Balance for Jackson is " + currentAccount.getBalance());
String hmm;
do
{
System.out.print("W)ithdraw, D)eposit, B)alance, or Q)uit: ");
String whatToDo = keyboard.readLine();
hmm = whatToDo;
if(whatToDo.equalsIgnoreCase("w"))
{
System.out.print("Enter withdrawal amount: ");
double withdraw = keyboard.readDouble();
currentAccount.withdraw(withdraw);
//System.out.println();
if(withdraw > currentAccount.getBalance())
System.out.println("Insufficient Funds...");
}
else
{
if(whatToDo.equalsIgnoreCase("d"))
{
System.out.print("Enter deposit amount: ");
double deposit = keyboard.readDouble();
currentAccount.deposit(deposit);
//System.out.println();
}
else
{
if(whatToDo.equalsIgnoreCase("b"))
{
System.out.println("Current Balance: " + currentAccount.getBalance());
// System.out.println();
}
else
{
if(whatToDo.equalsIgnoreCase("q"))
System.out.println("Have a nice whatever : )");
}
}
}
}
while(!(hmm.equalsIgnoreCase("q")));
}
}
OUTPUT:
--------------------Configuration: --------------------
Initial Balance for Jackson is 100.0
W)ithdraw, D)eposit, B)alance, or Q)uit: b
Current Balance: 100.0
W)ithdraw, D)eposit, B)alance, or Q)uit: w
Enter withdrawal amount: 98.91
Insufficient Funds...
W)ithdraw, D)eposit, B)alance, or Q)uit: b
Current Balance: 1.0900000000000034
W)ithdraw, D)eposit, B)alance, or Q)uit: