CS 392 Fall 2014
Exercise 01
Open up a Swift playground.
Write Swift code for a super simple Bank:
- A bank has customers.
- A customer has name and an account.
- An account has account number, balance, and owner.
- Write the
Customer
, Account
and Bank
classes.
- Money can be deposited or withdrawn from accounts.
- Write some test code to create a few Customer, Account and Bank objects;
add customers to the Bank, etc.
- Write
description
methods to print the account information of customers.
Objectives
- What’s the difference between
let
and var
?
- How do you initialize an object? i.e. What’s the equivalent of a constructor in Swift?
- How do you refer to the current object? i.e. What’s the equivalent of
this
in Swift?
- What’s
nil
?
- What’s an option type? E.g. What is the difference between
var account: Account?
and var account: Account
.
- How do you declare and use (i.e. iterate, access and modify) arrays?