File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ type Shape interface {
3030
3131// Rectangle is a struct that implements the Shape interface.
3232type Rectangle struct {
33- width, height float64
33+ name string
34+ width float64
35+ height float64
3436}
3537
3638// Area returns the area of the rectangle.
@@ -45,6 +47,7 @@ func (r Rectangle) Perimeter() float64 {
4547
4648// Circle is a struct that implements the Shape interface.
4749type Circle struct {
50+ name string
4851 radius float64
4952}
5053
@@ -60,16 +63,16 @@ func (c Circle) Perimeter() float64 {
6063
6164func main() {
6265 // Create a rectangle and a circle.
63- r := Rectangle{width: 10, height: 20}
64- c := Circle{radius: 5}
66+ r := Rectangle{name: "Rectangle", width: 10, height: 20}
67+ c := Circle{name: "Circle", radius: 5}
6568
6669 // Declare a slice of Shape interfaces.
6770 shapes := []Shape{r, c}
6871
6972 // Iterate over the shapes and print their area and perimeter.
7073 for _, shape := range shapes {
71- fmt.Println ("Area:" , shape.Area())
72- fmt.Println ("Perimeter:" , shape.Perimeter())
74+ fmt.Printf ("Area of shape %v is: %.2f\n", shape , shape.Area())
75+ fmt.Printf ("Perimeter of shape %v is: %.2f\n", shape , shape.Perimeter())
7376 fmt.Println("")
7477 }
7578}
You can’t perform that action at this time.
0 commit comments