From adc8a7604ad19a72ff2f15684e87fc30d75fa636 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 29 Feb 2024 11:38:11 -0600 Subject: [PATCH] start anew. re-think the GUI to add menu's to widgets --- .gitignore | 4 ++++ Makefile | 18 ++++++++++++++++ area.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 area.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e131cb2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.swp +go.mod +go.sum +junk diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..db875cc --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +all: + @#GO111MODULE=off go build + @GO111MODULE=off go vet -x + @echo this go library package builds okay + +build: + @GO111MODULE=off go build -x -o junk + ./junk + +goimports: + goimports -w *.go + +redomod: + rm -f go.* + goimports -w *.go + GO111MODULE= go mod init + GO111MODULE= go mod tidy + diff --git a/area.go b/area.go new file mode 100644 index 0000000..539e0d9 --- /dev/null +++ b/area.go @@ -0,0 +1,63 @@ +package main + +import ( + "fmt" + "math" +) + +type Circle struct { + Radius float64 +} + +func (c Circle) Area() float64 { + return math.Pi * math.Pow(c.Radius, 2) +} + +func (c Circle) String() string { + return fmt.Sprintf("Circle {Radius: %.2f}", c.Radius) +} + +type Square struct { + Width float64 + Height float64 +} + +func (s Square) Area() float64 { + return s.Width * s.Height +} + +func (s Square) String() string { + return fmt.Sprintf("Square {Width: %.2f, Height: %.2f}", s.Width, s.Height) +} + +type Sizer interface { + Area() float64 +} + +type Shaper interface { + Sizer + fmt.Stringer +} + +func main() { + c := Circle{Radius: 10} + PrintArea(c) + + s := Square{Height: 10, Width: 5} + PrintArea(s) + + l := Less(c, s) + fmt.Printf("%v is the smallest\n", l) + +} + +func Less(s1, s2 Sizer) Sizer { + if s1.Area() < s2.Area() { + return s1 + } + return s2 +} + +func PrintArea(s Shaper) { + fmt.Printf("area of %s is %.2f\n", s.String(), s.Area()) +}