-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bank.kt
217 lines (185 loc) · 6.73 KB
/
Bank.kt
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import java.text.SimpleDateFormat
import java.util.*
import java.io.File
import java.io.BufferedReader
import java.io.FileReader
class Bank() {
//var userInfo = "src/userInfo/yash.txt"
//var miniStatements = "src/miniStatements/yashStatements.txt"
var moneyInBank: Double= 0.0
fun deposit(amount : Double, accNum: String)
{
var fileName ="src/userInfo/" + accNum + ".txt"
var lines: List<String> = File(fileName).readLines()
var input = lines[0].split(",")
moneyInBank = input[4].toDouble()
moneyInBank += amount
var moneyString = moneyInBank.toString()
var inputData : String = input[0] +","+ input[1] +","+ input[2] +","+ input[3] +","+ moneyString
var file = File(fileName)
file.writeText(inputData)
var miniStatementFile = "src/ministatements/"+accNum + ".txt"
var minifile = File(miniStatementFile)
var fileExists = minifile.exists()
if(fileExists){
var lines: List<String> = File(miniStatementFile).readLines()
var linkedList = LinkedList(lines)
linkedList.push("Deposite on\t"+getCurrentDate(System.currentTimeMillis())+"\t Ammount +"+amount)
var final: String = linkedList.joinToString()
minifile.writeText(final)
//lines.forEach { line -> println(line) }
} else {
minifile.createNewFile()
minifile.writeText("Deposite on\t"+getCurrentDate(System.currentTimeMillis())+"\t Ammount +"+amount)
}
println("Deposite Successfull!!")
}
fun <T> linkedListOf(vararg elements: T): LinkedList<T> {
return LinkedList<T>(elements.toList())
}
fun withdrawl(amount : Double, accNum: String)
{
var fileName ="src/userInfo/" + accNum + ".txt"
var lines: List<String> = File(fileName).readLines()
var input = lines[0].split(",")
moneyInBank = input[4].toDouble()
if(moneyInBank>=amount)
{
moneyInBank -= amount
var moneyString = moneyInBank.toString()
var inputData : String = input[0] +","+ input[1] +","+ input[2] +","+ input[3] +","+ moneyString
var file = File(fileName)
file.writeText(inputData)
var miniStatementFile = "src/ministatements/"+accNum + ".txt"
var minifile = File(miniStatementFile)
var fileExists = minifile.exists()
if(fileExists){
var lines: List<String> = File(miniStatementFile).readLines()
var linkedList = LinkedList(lines)
linkedList.push("Withdraw on\t"+getCurrentDate(System.currentTimeMillis())+"\t Ammount -"+amount)
var final: String = linkedList.joinToString()
minifile.writeText(final)
//lines.forEach { line -> println(line) }
} else {
minifile.createNewFile()
minifile.writeText("Withdraw on\t"+getCurrentDate(System.currentTimeMillis())+"\t Ammount -"+amount)
}
println("Withdraw Successfull!!")
}
else
{
println("Insufficient Balace")
}
}
fun getCurrentDate(CurrentTimeinMillisecond: Long): String
{
val date= Date(CurrentTimeinMillisecond)
val formatter= SimpleDateFormat("MMM/dd/y: h:mm:a")
return formatter.format(date)
}
fun showMinistatement(accNum: String)
{
var miniStatementFile = "src/ministatements/"+accNum + ".txt"
var lines: List<String> = File(miniStatementFile).readLines()
var input = lines[0].split(",")
input.forEach { input -> println(input) }
println("---------------------------------------------------------------")
print("\t\t\t")
showBalance(accNum)
}
fun showBalance(accNum: String)
{
var fileName ="src/userInfo/" + accNum + ".txt"
var lines: List<String> = File(fileName).readLines()
var input = lines[0].split(",")
moneyInBank = input[4].toDouble()
println("Available Balance is "+moneyInBank)
}
/* fun transferBalance(sender: String, receiver: String, amount: Double)
{
var fileName ="src/userInfo/" + sender + ".txt"
var lines: List<String> = File(fileName).readLines()
var input = lines[0].split(",")
moneyInBank = input[4].toDouble()
if(moneyInBank>=amount)
{
moneyInBank -= amount
var moneyString = moneyInBank.toString()
var inputData : String = input[0] +","+ input[1] +","+ input[2] +","+ input[3] +","+ moneyString
var file = File(fileName)
file.writeText(inputData)
var miniStatementFile = "src/ministatements/"+sender + ".txt"
var minifile = File(miniStatementFile)
var fileExists = minifile.exists()
if(fileExists){
var lines: List<String> = File(miniStatementFile).readLines()
var linkedList = LinkedList(lines)
linkedList.push("Transfered to\t "+receiver+"\t"+getCurrentDate(System.currentTimeMillis())+"\t Ammount -"+amount)
var final: String = linkedList.joinToString()
minifile.writeText(final)
//lines.forEach { line -> println(line) }
} else {
minifile.createNewFile()
minifile.writeText("Transfered to\t "+receiver+"\t"+getCurrentDate(System.currentTimeMillis())+"\t Ammount -"+amount)
}
}
else
{
println("Insufficient Balace")
}
var receiverfileName ="src/userInfo/" + sender + ".txt"
var receiverlines: List<String> = File(receiverfileName).readLines()
var receiverinput = receiverlines[0].split(",")
var receivermoneyInBank = input[4].toDouble()
var receiverinput = lines[0].split(",")
moneyInBank = receiverinput[4].toDouble()
moneyInBank += amount
var moneyString = moneyInBank.toString()
var inputData : String = input[0] +","+ input[1] +","+ input[2] +","+ input[3] +","+ moneyString
var file = File(fileName)
file.writeText(inputData)
var miniStatementFile = "src/ministatements/"+accNum + ".txt"
var minifile = File(miniStatementFile)
var fileExists = minifile.exists()
if(fileExists){
var lines: List<String> = File(miniStatementFile).readLines()
var linkedList = LinkedList(lines)
linkedList.push("Deposite on\t"+getCurrentDate(System.currentTimeMillis())+"\t Ammount +"+amount)
var final: String = linkedList.joinToString()
minifile.writeText(final)
//lines.forEach { line -> println(line) }
} else {
minifile.createNewFile()
minifile.writeText("Deposite on\t"+getCurrentDate(System.currentTimeMillis())+"\t Ammount +"+amount)
}
}
*/
fun registration(name : String,accNum : String, pass: String, mob: String, amount: Double)
{
var data: String = name + "," + accNum + "," + pass + "," + mob +"," + amount.toString()
var fileName = accNum + ".txt"
var file = File("src/userInfo/"+fileName)
val isNewFileCreated :Boolean = file.createNewFile()
file.writeText(data)
if(isNewFileCreated){
println("Account created successfully.")
} else{
println("Account number already exists.")
}
}
fun checkLogin(accNum: String, pass: String): Boolean
{
try{
var fileName ="src/userInfo/" + accNum + ".txt"
var lines: List<String> = File(fileName).readLines()
var input = lines[0].split(",")
if(input[2].equals(pass))
return true
else
return false
}catch(er : Exception)
{
return false
}
}
}