Professional Documents
Culture Documents
Run Savings Account
Run Savings Account
Run Savings Account
import java.util.Scanner;
class SavingsAccount {
private double balance;
public static double interestRate = 0;
public SavingsAccount() {
balance = 0;
}
char choice;
while (true) {
System.out.print("\nEnter D for another deposit or W for withdraw: ");
choice = Character.toUpperCase(sc.next().trim().charAt(0));
if (choice == 'D') {
System.out.print("Enter amount to be deposited: ");
savings.deposit(sc.nextDouble());
}
else if (choice == 'W') {
System.out.print("Enter amount to be withdrawn: ");
double withdrawn = savings.withdraw(sc.nextDouble());
if (withdrawn == 0) {
System.out.println("-> You don't have sufficient balance!");
}
else {
System.out.println("-> Amount successfully withdrawn!");
}
}
else {
System.out.println("-> Invalid option selected! Try again...");
continue;
}