-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencapsulation.dart
More file actions
102 lines (66 loc) · 1.42 KB
/
encapsulation.dart
File metadata and controls
102 lines (66 loc) · 1.42 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
void main(){
print(' ');
print('Restaurant Class');
print(' ');
Restaurant KFC = Restaurant();
KFC.order('ckn fry');
print(KFC.ResID);
KFC.setID = 54554;
print(KFC.ResID);
print(' ');
print('Bank Account Class');
print(' ');
BankAccount account = BankAccount('1122');
print('Your Balance is ${account.getBalance('1122')}');
account.withdraw(100);
account.deposit(100);
print('Your Balance is ${account.getBalance('1122')}');
print(' ');
print('Interface Class');
print(' ');
}
class Restaurant{
int _id = 26565;
//getter method
int get ResID => _id;
set setID(int value){
_id = value;
}
order(String item){
print('$item Ordered');
_prepareItem(item);
_shopping(item);
}
_prepareItem(String item){
print('$item preparing');
}
_shopping(String item){
print('$item shopping');
}
}
class BankAccount{
double _balance = 0;
final String _pin;
BankAccount(this._pin){
print('New Account Created');
}
// double get balance => _balance;
double getBalance(String pin){
if(pin ==_pin){
return _balance;
}else{
throw Exception('Unauthorized Access');
}
}
deposit(double amount){
_balance +=amount;
print('Deposited: $amount');
}
withdraw(double amount){
if(amount > 0 && amount <= _balance){
_balance -= amount;
}else{
print('An Invalid withdrawal amount');
}
}
}