-
-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code to remove unnecessary package and unused imports
- Loading branch information
1 parent
c0d5f72
commit 61b80de
Showing
5 changed files
with
177 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,36 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
type Printer interface { | ||
printInfo() | ||
type shape interface { | ||
area() float64 | ||
} | ||
|
||
|
||
type Book struct { | ||
Title string | ||
Price float32 | ||
type circle struct { | ||
radius float64 | ||
} | ||
|
||
type Drink struct { | ||
Name string | ||
Price float32 | ||
type rectangle struct { | ||
width float64 | ||
length float64 | ||
} | ||
|
||
func (b Book) printInfo() { | ||
fmt.Println("Book Title:", b.Title, "Price:", b.Price) | ||
func (r rectangle) area() float64 { | ||
return r.length * r.width | ||
} | ||
|
||
func (d Drink) printInfo() { | ||
fmt.Println("Drink Name:", d.Name, "Price:", d.Price) | ||
func (c circle) area() float64 { | ||
return 2 * math.Pi * c.radius | ||
} | ||
|
||
func main() { | ||
book := Book{Title: "The Alchemist", Price: 9.99} | ||
drink := Drink{Name: "Coke", Price: 1.99} | ||
|
||
// book.printInfo() | ||
// drink.printInfo() | ||
myRectangle := rectangle{width: 8, length: 10} | ||
fmt.Println(myRectangle.area()) | ||
|
||
info := []Printer{book, drink} | ||
myCircle := circle{radius: 10} | ||
fmt.Println(myCircle.area()) | ||
|
||
info[0].printInfo() | ||
info[1].printInfo() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters