2024-09-11 06:55:19 +00:00
|
|
|
package shapes
|
|
|
|
|
2024-09-11 07:17:21 +00:00
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
)
|
2024-09-11 07:06:46 +00:00
|
|
|
|
2024-09-11 07:10:19 +00:00
|
|
|
type Shape interface {
|
|
|
|
Area() float64
|
|
|
|
}
|
|
|
|
|
2024-09-11 06:58:04 +00:00
|
|
|
type Rectangle struct {
|
|
|
|
Width float64
|
|
|
|
Height float64
|
2024-09-11 06:55:19 +00:00
|
|
|
}
|
|
|
|
|
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
|
2024-09-11 06:55:19 +00:00
|
|
|
}
|
2024-09-11 07:06:46 +00:00
|
|
|
|
2024-09-11 07:17:21 +00:00
|
|
|
type Circle struct {
|
|
|
|
Radius float64
|
|
|
|
}
|
|
|
|
|
2024-09-11 07:06:46 +00:00
|
|
|
func (c Circle) Area() float64 {
|
|
|
|
return c.Radius * c.Radius * math.Pi
|
|
|
|
}
|
2024-09-11 07:17:21 +00:00
|
|
|
|
|
|
|
type Triangle struct {
|
|
|
|
Width float64
|
|
|
|
Height float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t Triangle) Area() float64 {
|
|
|
|
return t.Width * t.Height * 0.5
|
|
|
|
}
|