-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
59 lines (53 loc) · 1.94 KB
/
Account.java
File metadata and controls
59 lines (53 loc) · 1.94 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
public class Account {
private int accountNumber;
private String accountHolderName;
private double balance;
private String email;
private String phoneNumber;
public Account(int accountNumber, String accountHolderName, double initialBalance, String email, String phoneNumber) {
this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.balance = initialBalance;
this.email = email;
this.phoneNumber = phoneNumber;
}
// Deposit money
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Amount deposited successfully. Current balance: " + balance);
} else {
System.out.println("Deposit amount must be positive.");
}
}
// Withdraw money
public void withdraw(double amount) {
if (amount > 0) {
if (amount <= balance) {
balance -= amount;
System.out.println("Amount withdrawn successfully. Current balance: " + balance);
} else {
System.out.println("Insufficient balance.");
}
} else {
System.out.println("Withdrawal amount must be positive.");
}
}
// Display account details
public void displayAccountDetails() {
System.out.println("Account Number: " + accountNumber);
System.out.println("Account Holder Name: " + accountHolderName);
System.out.println("Balance: " + balance);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNumber);
}
// Update contact details
public void updateContactDetails(String email, String phoneNumber) {
this.email = email;
this.phoneNumber = phoneNumber;
System.out.println("Contact details updated successfully.");
}
public int getAccountNumber() {
return accountNumber;
}
}