Skip to content

Instantly share code, notes, and snippets.

@yaravind
Created January 9, 2017 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaravind/b01f90b3453d94798dbc6ab801a229ca to your computer and use it in GitHub Desktop.
Save yaravind/b01f90b3453d94798dbc6ab801a229ca to your computer and use it in GitHub Desktop.
func main() {
aliceAcct := OpenSavingsAccount("12345", "Alice", time.Date(1999, time.January, 03, 0, 0, 0, 0, time.UTC))
fmt.Println("Alice's account =", aliceAcct)
aliceAcct.Deposit(Money(100.0))
fmt.Println("Alice's account (after deposit) =", aliceAcct)
if err := aliceAcct.Withdraw(Money(10)); err != nil {
fmt.Println(err)
} else {
fmt.Println("Alice's account (after withdrawl) =", aliceAcct)
}
const overDraft = false
bobAcct := OpenCheckingAccount("98765", "Bob", time.Date(1997, time.April, 03, 0, 0, 0, 0, time.UTC), overDraft)
fmt.Println("\nBob's account =", bobAcct)
bobAcct.Deposit(Money(100.0))
fmt.Println("Bob's account (after deposit) =", bobAcct)
if err := bobAcct.Withdraw(Money(77)); err != nil {
fmt.Println(err)
} else {
fmt.Println("Bob's account (after withdrawl) =", bobAcct)
}
fmt.Println("\nTransfering 10.0 from Alice to Bob's acct")
if err := Transfer(aliceAcct, bobAcct, Money(76.0)); err != nil {
fmt.Println(err)
}
fmt.Println("Alice's account =", aliceAcct)
fmt.Println("Bob's account =", bobAcct)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment