go-by-test/shapes/shapes.go

25 lines
346 B
Go
Raw Normal View History

package shapes
import "math"
2024-09-11 06:58:04 +00:00
type Rectangle struct {
Width float64
Height float64
}
type Circle struct {
Radius float64
}
2024-09-11 07:03:57 +00:00
func (r Rectangle) Perimeter() float64 {
2024-09-11 06:58:04 +00:00
return 2 * (r.Width + r.Height)
}
2024-09-11 07:03:57 +00:00
func (r Rectangle) Area() float64 {
2024-09-11 06:58:04 +00:00
return r.Width * r.Height
}
func (c Circle) Area() float64 {
return c.Radius * c.Radius * math.Pi
}