Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // BankAccount.swift
- // Ishankumar-Patel_COMP2125_Lab02
- //
- // Created by Ishankumar Patel on 2019-06-19.
- // Copyright © 2019 Ishankumar Patel. All rights reserved.
- //
- import Foundation
- public class BankAccount
- {
- public var accountNumber:String = ""
- {
- didSet{
- print("The value of accountNumber is updated")
- }
- }
- public var customerName:String = ""
- {
- didSet{
- print("The value of customerName is updated")
- }
- }
- public var annualInterest:Double = 0.00
- {
- didSet{
- print("Annual Interest rate is updated")
- }
- }
- public var accountBalance:Double = 0.00
- {
- didSet{
- print("Account balance is updated")
- }
- }
- public init()
- {
- accountNumber = ""
- customerName = ""
- annualInterest = 0.00
- accountBalance = 0.00
- }
- public init(accountNumber:String,customerName:String,annualInterest:Double,accountBalance:Double)
- {
- if !accountNumber.isEmpty
- {
- self.accountNumber = accountNumber
- }
- if !customerName.isEmpty
- {
- self.customerName = customerName
- }
- if annualInterest >= 0 && annualInterest <= 2
- {
- self.annualInterest = annualInterest
- }
- if accountBalance > 0
- {
- self.accountBalance = accountBalance
- }
- }
- public var description :String
- {
- get{
- return "Account Number: \(accountNumber)\n Customer Name: \(customerName) \n Annual Interest \(annualInterest)"
- }
- }
- func credit(amount:Double)
- {
- if amount > 0
- {
- accountBalance = accountBalance + amount
- }
- }
- func debit(amount:Double)
- {
- if amount <= accountBalance && amount > 0
- {
- accountBalance = accountBalance - amount
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement