Skip to content
Snippets Groups Projects
Commit 95391ba7 authored by Martin Schmollinger's avatar Martin Schmollinger
Browse files

Solution to exercise of unit 04-02

parent cf413363
No related branches found
No related tags found
No related merge requests found
module gitlab.reutlingen-university.de/go-exercises/go-starter/exercise_0402
go 1.20
package main
import (
"errors"
"fmt"
)
type BankAccount struct {
balance float32
limit float32
}
func (ba *BankAccount) Withdraw(amount float32) error {
if amount > ba.balance+ba.limit {
return errors.New("amount currently not available")
} else {
ba.balance -= amount
return nil
}
}
func main() {
ba := BankAccount{
balance: 1000.0,
limit: 3000.0,
}
fmt.Printf("%v\n", ba)
if err := ba.Withdraw(5000); err != nil {
fmt.Println(err.Error())
}
fmt.Printf("%v\n", ba)
if err := ba.Withdraw(1000); err != nil {
fmt.Println(err.Error())
}
fmt.Printf("%v\n", ba)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment