-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccountManagement.java
More file actions
103 lines (84 loc) · 3.2 KB
/
BankAccountManagement.java
File metadata and controls
103 lines (84 loc) · 3.2 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.util.Scanner;
class BankAccount {
private String accountHolder;
private int accountNumber;
private double balance;
public BankAccount(String accountHolder, int accountNumber, double balance) {
this.accountHolder = accountHolder;
this.accountNumber = accountNumber;
this.balance = balance;
}
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Successfully deposited: $" + amount);
} else {
System.out.println("Invalid deposit amount!");
}
}
public void withdraw(double amount) {
if (amount > 0) {
if (amount <= balance) {
balance -= amount;
System.out.println("Successfully withdrew: $" + amount);
} else {
System.out.println("Insufficient balance!");
}
} else {
System.out.println("Invalid withdrawal amount!");
}
}
public void checkBalance() {
System.out.println("Current balance: $" + balance);
}
public void displayAccountInfo() {
System.out.println("Account Holder: " + accountHolder);
System.out.println("Account Number: " + accountNumber);
System.out.println("Balance: $" + balance);
}
}
public class BankAccountManagement {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Account Holder Name: ");
String name = sc.nextLine();
System.out.print("Enter Account Number: ");
int accNum = sc.nextInt();
BankAccount account = new BankAccount(name, accNum, 0.0);
int choice;
do {
System.out.println("\n=== Bank Menu ===");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Check Balance");
System.out.println("4. Display Account Info");
System.out.println("5. Exit");
System.out.print("Choose an option: ");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter amount to deposit: ");
double depositAmount = sc.nextDouble();
account.deposit(depositAmount);
break;
case 2:
System.out.print("Enter amount to withdraw: ");
double withdrawAmount = sc.nextDouble();
account.withdraw(withdrawAmount);
break;
case 3:
account.checkBalance();
break;
case 4:
account.displayAccountInfo();
break;
case 5:
System.out.println("Thank you for using the Bank Account Management System!");
break;
default:
System.out.println("Invalid choice! Try again.");
}
} while (choice != 5);
sc.close();
}
}