var atmarray = arrayListOf<ATM>()
class ATM(
val AccountName:String="",
val Pin:Int=0,
val IntialDeposit:Double=0.0
)
fun main(args: Array<String>) {
mainmenu()
}
fun mainmenu(){
println("WELCOME TO BANK AL BILAL ATM MACHINE")
println("1- Add Account\n2- Login Account\n3-Exit")
var input1= readLine()!!.toInt()
when(input1){
1->add()
2->login()
3-> Exit()
}
}
fun add(){
println("Enter Your Name")
val Name= readLine()!!.toString()
println("Enter Your 4-Digit Account Pin")
var Pin= readLine()!!.toInt()
println("Confirm Your 4-Digit Account Pin")
var Pin1= readLine()!!.toInt()
if (Pin!=Pin1){
println("Sorry Your Pin didn't Match, Try Again")
add()
}
else{
println("Pin Verified Successfully")
}
println("Enter the Amount to Deposit")
var FirstDeposit= readLine()!!.toDouble()
atmarray.add(ATM(Name,Pin,FirstDeposit ))
mainmenu()
}
fun login(){
println("Enter your Account Name")
var AcName=readLine()!!.toString()
println("Enter your 4-digit Account Pin")
var AcPin= readLine()!!.toInt()
// Need help here how to verify login by accessing atmarray class
}
fun Exit(){
println("GOOD BYE VALUEABLE CUSTOMER")
mainmenu()
}
注意:我试图为用户创建一个登录部分,但是在访问上面的atmarray类时遇到问题。我想知道如何通过登录部分中的其他方式访问atmarray类中可用的帐户名和密码。
答案 0 :(得分:0)
atmarray.find { account -> account.AccountName == AcName }?.let { selectedAccount ->
if (selectedAccount.Pin == AcPin) {
//login success
}
}