Knaph

Pointers, Methods, and Interfaces45 of 62

Shape Interface

Read three numbers — a rectangle's width and height, and a circle's radius — and print the sum of their areas, formatted to two decimal places (fmt.Printf("%.2f\n", total) in the starter code already does the formatting for you). Implement Area() float64 as a method on Rectangle and on Circle so that both types satisfy the Shape interface already defined in the starter code. Use 3.14159 for pi. The main function already puts both shapes into a single []Shape slice and sums their areas through the interface — you shouldn't need to change anything below the two TODOs.

Sign in to try this exercise.