Guest User

Untitled

a guest
May 20th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. class ATM
  2.  
  3. def start(config)
  4. customer = Customer.new("","","","")
  5. customer.account = customer.get_account
  6. if customer.existing_account?(config,customer.account)
  7. customer.password = customer.get_password
  8. if customer.verified_password?(config,customer.account,customer.password)
  9. customer.name = customer.get_name(config,customer.account)
  10. customer.balance = customer.get_balance(config,customer.account)
  11. puts "Hello, #{customer.name}!"
  12. #menu(config,account,customer)
  13. else puts "ERROR: ACCOUNT NUMBER AND PASSWORD DON'T MATCH"
  14. start(config)
  15. end
  16. else puts "ERROR: ACCOUNT NUMBER NOT FOUND"
  17. start(config)
  18. end
  19. end
  20.  
  21.  
  22. end
  23.  
  24.  
  25. class Customer
  26.  
  27. attr_accessor :account, :password, :name, :balance
  28.  
  29. def initialize(account,password,name,balance)
  30. @accont = account
  31. @password = password
  32. @name = name
  33. @balance = balance
  34. end
  35.  
  36. def get_account
  37. print "Please Enter Your Account Number: "
  38. acc = gets
  39. account = acc.to_i
  40. end
  41.  
  42. def existing_account?(config,account)
  43. return true if config['accounts'].has_key?(account)
  44. false
  45. end
  46.  
  47. def get_password
  48. print "Please Enter Your Password: "
  49. pass = gets
  50. pasword = pass.chomp
  51. end
  52.  
  53. def verified_password?(config,account,password)
  54. return true if config['accounts'][account]['password'] == password
  55. false
  56. end
  57.  
  58. def get_name(config,account)
  59. name = config['accounts'][account]['name']
  60. end
  61.  
  62. def get_balance(config,account)
  63. balance = config['accounts'][account]['balance']
  64. end
  65.  
  66. end
  67.  
  68. config = {"banknotes"=>{500=>0, 200=>0, 100=>2, 50=>1, 20=>2, 10=>4, 5=>1, 2=>0, 1=>2}, "accounts"=>{3321=>{"name"=>"Volodymyr", "password"=>"mypass", "balance"=>422}, 5922=>{"name"=>"Iryna", "password"=>"1111", "balance"=>5301}}}
  69.  
  70. atm = ATM.new
  71. atm.start(config)
Add Comment
Please, Sign In to add comment