-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
70 lines (56 loc) · 1.97 KB
/
BankAccount.java
File metadata and controls
70 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.Scanner;
public class BankAccount {
String accountHolder;
double balance;
public BankAccount(String name) {
accountHolder = name;
balance = 0.0;
}
public void deposit (double amount) {
balance += amount;
}
public void withdraw (double amount) {
if (amount > balance) {
System.out.println("Insufficient Balance! You can't withdraw anymore.....");
} else {
balance -= amount;
}
}
public void checkbalance () {
System.out.println("Current Balance: " + balance);;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();
BankAccount account = new BankAccount(name);
while (true) {
System.out.println("choose an option: ");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Check Balance");
System.out.println("4. Exit");
int choice = scanner.nextInt();
switch(choice){
case 1:
System.out.println("Enter deposit amount: ");
double depositAmount = scanner.nextDouble();
account.deposit(depositAmount);
break;
case 2:
System.out.println("Enter withdrawal amount: ");
double withdrawalAmount = scanner.nextDouble();
account.withdraw(withdrawalAmount);
break;
case 3:
account.checkbalance();
break;
case 4:
System.out.println("exiting..............");
scanner.close();
return;
default:
System.out.println("Invalid choice!!!Please try again........");
}
}
}
}