The objective of this assignment is to create a set of classes in Swift to represent a simple banking system. This will demonstrate your understanding of inheritance, method overloading, method overriding, computed properties, initializers, and deinitializers.
BankAccount
SavingsAccount
(inherits fromBankAccount
)CurrentAccount
(inherits fromBankAccount
)
Properties:
accountNumber: String
balance: Double
(computed property)
Initializers:
- Designated initializer that takes
accountNumber
andinitialBalance
.
Methods:
deposit(amount: Double)
withdraw(amount: Double)
(virtual method to be overridden in subclasses)
Deinitializer:
- Print a message indicating the account is being closed.
Inherits from:
BankAccount
Additional Properties:
interestRate: Double
Initializers:
- Designated initializer that takes
accountNumber
,initialBalance
, andinterestRate
.
Methods:
applyInterest()
- Override
withdraw(amount: Double)
to impose a condition: withdraw only if balance remains above a minimum limit ($100).
Computed Properties:
balance
to include interest.
Inherits from:
BankAccount
Additional Properties:
overdraftLimit: Double
Initializers:
- Designated initializer that takes
accountNumber
,initialBalance
, andoverdraftLimit
.
Methods:
- Override
withdraw(amount: Double)
to allow overdraft up to the overdraftLimit.
Computed Properties:
balance
to reflect the effective available balance considering the overdraft.
- Implement all required classes and methods.
- Demonstrate method overloading by creating a method
statement
inBankAccount
that shows account details with different formats. - Provide an example of how these classes would be used in a main program.