diff --git a/star-shapes-mk2/go.mod b/star-shapes-mk2/go.mod new file mode 100644 index 0000000..ccfa1fe --- /dev/null +++ b/star-shapes-mk2/go.mod @@ -0,0 +1,3 @@ +module star-shapes-mk2 + +go 1.22.2 diff --git a/star-shapes-mk2/main.go b/star-shapes-mk2/main.go new file mode 100644 index 0000000..2e3d016 --- /dev/null +++ b/star-shapes-mk2/main.go @@ -0,0 +1,47 @@ +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()) +}