Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filipbankaccount #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions FilipKrstevski/bankaccount/bank_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package account

import "sync"

type (
Account interface {
Close() (payout int64, ok bool)
Balance() (balance int64, ok bool)
Deposit(amount int64) (newBalance int64, ok bool)
}
)

type accountData struct {
balance int64
open bool
mux sync.Mutex
}

func Open(initialDeposit int64) Account {

if initialDeposit < 0 {
return nil
}

var acc Account
acc = &accountData{
balance: initialDeposit,
open: true,
}

return acc
}

func (acc *accountData) Close() (payout int64, ok bool) {
acc.mux.Lock()
defer acc.mux.Unlock()

if !acc.open {
return 0, false
}

acc.open = false
return acc.balance, true
}

func (acc *accountData) Balance() (balance int64, ok bool) {

acc.mux.Lock()
defer acc.mux.Unlock()

if !acc.open {
return 0, false
}

return acc.balance, true
}

func (acc *accountData) Deposit(amount int64) (int64, bool) {

acc.mux.Lock()
defer acc.mux.Unlock()

if !acc.open {
return 0, false
}

if acc.balance+amount < 0 {
return acc.balance, false
}

acc.balance += amount
return acc.balance, true
}
44 changes: 44 additions & 0 deletions FilipKrstevski/house/house.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package house
import "strings"
func Verse(v int) string {
rhyme := "This is the "
end := verses[0].object + " that " + verses[0].action + "."
if v == 1 {
return rhyme + end
}
rhyme += verses[v-1].object
for ; v > 1; v-- {
rhyme += "\nthat " + verses[v-1].action + " the "
if v-1 == 1 {
rhyme += end
} else {
rhyme += verses[v-2].object
}
}
return rhyme
}
func Song() string {
allverses := []string{}
for v := 1; v <= len(verses); v++ {
allverses = append(allverses, Verse(v))
}
return strings.Join(allverses, "\n\n")
}
var verses = []verse{
verse{object: "house", action: "Jack built"},
verse{object: "malt", action: "lay in"},
verse{object: "rat", action: "ate"},
verse{object: "cat", action: "killed"},
verse{object: "dog", action: "worried"},
verse{object: "cow with the crumpled horn", action: "tossed"},
verse{object: "maiden all forlorn", action: "milked"},
verse{object: "man all tattered and torn", action: "kissed"},
verse{object: "priest all shaven and shorn", action: "married"},
verse{object: "rooster that crowed in the morn", action: "woke"},
verse{object: "farmer sowing his corn", action: "kept"},
verse{object: "horse and the hound and the horn", action: "belonged to"},
}
type verse struct {
object string
action string
}