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

Solution to exercise of unit 03-04

parent e304a4f1
No related branches found
No related tags found
No related merge requests found
module gitlab.reutlingen-university.de/go-exercises/go-starter/exercise_0303
go 1.20
package main
import "fmt"
type Areaer interface {
Area() int
}
type Rectangle struct {
length int
width int
}
func (r Rectangle) Area() int {
return r.length * r.width
}
func (r *Rectangle) SetWidth(width int) {
r.width = width
}
func (r Rectangle) String() string {
return fmt.Sprintf("{l: %d, w: %d}", r.length, r.width)
}
func createShape() Areaer {
return Rectangle{length: 10, width: 5}
}
func main() {
r := Rectangle{length: 10, width: 5}
r.SetWidth(9)
fmt.Println(r.Area())
s := createShape()
fmt.Println(s.Area())
fmt.Println(r)
}
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