Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import java.io.File
  2.  
  3. class CashMachine (){
  4. var note : MutableList<String> = ArrayList()
  5. fun AddMoney(index:Int){
  6. note[index-1]= (note[index-1].toInt() + 1).toString()
  7. println(note[index-1])
  8. write_to_txt ()
  9. }
  10. fun Withdraw(index:Int){
  11. note[index-1]= (note[index-1].toInt() - 1).toString()
  12. write_to_txt ()
  13. }
  14. fun write_to_txt (){
  15. File("ATM.txt").writeText("")
  16. note.forEach {
  17. File("ATM.txt").appendText(it+System.getProperty("line.separator"))
  18. }
  19. }
  20.  
  21. fun getBalance(){
  22. File("ATM.txt").forEachLine {
  23. note.add(it)
  24. }
  25. }
  26. fun checkWithdraw(test:Int): Boolean{
  27. var withdraw=test
  28. var cashammount :Int
  29. val cash_table: IntArray = intArrayOf(10,20,50,100,200,500)
  30. var check :Int
  31. var i:Int = 5
  32. while(withdraw>0 && i>=0){
  33. cashammount= withdraw/cash_table[i]
  34. check= cashammount - note[i].toInt()
  35. when (check>=0){
  36. true-> {
  37. withdraw -= (note[i].toInt() * cash_table[i])
  38. }
  39. false->{
  40. withdraw-= (cashammount * cash_table[i])
  41. }
  42. }
  43. i-=1
  44. }
  45. println(withdraw)
  46. when(withdraw==0){
  47. true-> return true
  48. false -> return false
  49. }
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement