Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File
- class CashMachine (){
- var note : MutableList<String> = ArrayList()
- fun AddMoney(index:Int){
- note[index-1]= (note[index-1].toInt() + 1).toString()
- println(note[index-1])
- write_to_txt ()
- }
- fun Withdraw(index:Int){
- note[index-1]= (note[index-1].toInt() - 1).toString()
- write_to_txt ()
- }
- fun write_to_txt (){
- File("ATM.txt").writeText("")
- note.forEach {
- File("ATM.txt").appendText(it+System.getProperty("line.separator"))
- }
- }
- fun getBalance(){
- File("ATM.txt").forEachLine {
- note.add(it)
- }
- }
- fun checkWithdraw(test:Int): Boolean{
- var withdraw=test
- var cashammount :Int
- val cash_table: IntArray = intArrayOf(10,20,50,100,200,500)
- var check :Int
- var i:Int = 5
- while(withdraw>0 && i>=0){
- cashammount= withdraw/cash_table[i]
- check= cashammount - note[i].toInt()
- when (check>=0){
- true-> {
- withdraw -= (note[i].toInt() * cash_table[i])
- }
- false->{
- withdraw-= (cashammount * cash_table[i])
- }
- }
- i-=1
- }
- println(withdraw)
- when(withdraw==0){
- true-> return true
- false -> return false
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement