Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. //
  2. // BankAccount.swift
  3. // Ishankumar-Patel_COMP2125_Lab02
  4. //
  5. // Created by Ishankumar Patel on 2019-06-19.
  6. // Copyright © 2019 Ishankumar Patel. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10.  
  11. public class BankAccount
  12. {
  13. public var accountNumber:String = ""
  14. {
  15. didSet{
  16. print("The value of accountNumber is updated")
  17. }
  18. }
  19. public var customerName:String = ""
  20. {
  21. didSet{
  22. print("The value of customerName is updated")
  23. }
  24. }
  25. public var annualInterest:Double = 0.00
  26. {
  27. didSet{
  28. print("Annual Interest rate is updated")
  29. }
  30. }
  31. public var accountBalance:Double = 0.00
  32. {
  33. didSet{
  34. print("Account balance is updated")
  35. }
  36. }
  37.  
  38. public init()
  39. {
  40. accountNumber = ""
  41. customerName = ""
  42. annualInterest = 0.00
  43. accountBalance = 0.00
  44.  
  45.  
  46. }
  47. public init(accountNumber:String,customerName:String,annualInterest:Double,accountBalance:Double)
  48. {
  49. if !accountNumber.isEmpty
  50. {
  51. self.accountNumber = accountNumber
  52. }
  53. if !customerName.isEmpty
  54. {
  55. self.customerName = customerName
  56. }
  57. if annualInterest >= 0 && annualInterest <= 2
  58. {
  59. self.annualInterest = annualInterest
  60. }
  61. if accountBalance > 0
  62. {
  63. self.accountBalance = accountBalance
  64. }
  65.  
  66. }
  67.  
  68. public var description :String
  69. {
  70. get{
  71. return "Account Number: \(accountNumber)\n Customer Name: \(customerName) \n Annual Interest \(annualInterest)"
  72. }
  73. }
  74.  
  75. func credit(amount:Double)
  76. {
  77. if amount > 0
  78. {
  79. accountBalance = accountBalance + amount
  80. }
  81. }
  82.  
  83. func debit(amount:Double)
  84. {
  85. if amount <= accountBalance && amount > 0
  86. {
  87. accountBalance = accountBalance - amount
  88. }
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement