48 lines
601 B
Go
48 lines
601 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
type Shaper interface {
|
||
|
Shape(int) Square
|
||
|
}
|
||
|
|
||
|
type Square struct {
|
||
|
form string
|
||
|
quantity int
|
||
|
}
|
||
|
|
||
|
func (s Square) Shape(num int) Square {
|
||
|
for i := 0; i < num; i++ {
|
||
|
for i := 0; i < num; i++ {
|
||
|
s.form += "* "
|
||
|
}
|
||
|
s.form += "\n"
|
||
|
}
|
||
|
|
||
|
s.quantity = num
|
||
|
return s
|
||
|
}
|
||
|
|
||
|
func showShape(s Shaper, num int) {
|
||
|
fmt.Println(s.Shape(num).form)
|
||
|
}
|
||
|
|
||
|
func getNumberStars() int {
|
||
|
numStr := os.Args[1]
|
||
|
num, err := strconv.Atoi(numStr)
|
||
|
if err != nil {
|
||
|
log.Panicln(err)
|
||
|
}
|
||
|
return num
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
s := Square{}
|
||
|
showShape(s, getNumberStars())
|
||
|
}
|