-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
56 lines (49 loc) · 1.49 KB
/
Copy pathAccount.java
File metadata and controls
56 lines (49 loc) · 1.49 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
class Account {
private int accountNumber;
private String holderName;
private double balance;
private int pin;
Account(int accountNumber, String holderName, int pin){
this.accountNumber = accountNumber;
this.holderName = holderName;
this.balance = 0;
this.pin = pin;
}
public int getAccountNumber(){
return accountNumber;
}
public double getBalance(){
return balance;
}
public boolean authenticate(int enteredPin){
return (this.pin == enteredPin);
}
public void deposit(double amount){
if(amount <= 0){
System.out.println("Amount must be greater than 0!");
return;
}
balance += amount;
System.out.println("Amount Deposited Successfully!");
}
public void withdraw(double amount){
if(amount <= 0){
System.out.println("Amount must be greater than 0!");
return;
}
if(amount > balance){
System.out.println("Isufficient Balance!");
return;
}
balance -= amount;
System.out.println("Amount Withdrawn Successfully!");
}
void display(){
System.out.println("----------------------");
System.out.println("Account Number: " + accountNumber);
System.out.println("Holder Name: " + holderName);
System.out.println("Balance: " + balance);
System.out.println("----------------------");
System.out.println();
}
}