Log in

View Full Version : Java - Bank Account


Jess
September 24th, 2013, 10:35 PM
package edu.pitt.ChenHomework4;
import java.util.Scanner;
public class BankAccount {


public static void main(String[] args) {
String accountStatus = "active"; // is the account active or not?
double accountBalance = 1000.00; // initial account balance

Scanner in = new Scanner(System.in); // the Scanner class to get user input
System.out.print("Please enter the amount that you would like to withdraw. " +
"Enter -1 to exit the program: "); // Asks user to enter amount, with an input to enter
// if user wishes to exit
double withdrawalAmount = in.nextDouble(); // withdrawal amount is the amount user entered

/*if the account is active, and the account balance is greater or equal to the
* withdrawal amount, print out the updated account balance by subtracting the
* withdrawal amount from the total account balance.
*/
do {
} while (withdrawalAmount == -1);
if (accountStatus.equals("active") && accountBalance >= withdrawalAmount) {
System.out.println(accountBalance - withdrawalAmount);
}
else {
System.out.println("Account balance is insufficient.");
/*If withdrawal amount is more than the account balance, it will say so and nothing will be
* withdrawn
*/
}

}
}




Directions/Requirements:
Add a do/while loop to your program (you’ll have to place most of your logic inside the while loop) that would keep asking the user to enter a withdrawal amount and perform the withdrawal until the user enters -1
Keep in mind that every time a withdrawal amount is entered, you still have to check if the user
has a sufficient balance and if the account is active. All calculations must be correct
Your program must print the account balance after each withdrawal.

My code is wrong, need a bit of help. Due tomorrow, so please reply before tomorrow midnight EST

TheMatrix
September 25th, 2013, 07:43 AM
Your do...while loop is empty. You should probably place everything from the scanner onwards inside that loop.

Jess
September 25th, 2013, 10:58 PM
I managed to get it, thanks anyways