From 943191e9dd7e86fe64bbab67538bbe7fae57518a Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 31 Jan 2024 14:45:10 -0500 Subject: [PATCH] Finished chap 10 and 11 --- playground/calendar.go | 20 +++++++++++++++++++- playground/fuel.go | 17 +++++++++++++++++ playground/go.mod | 1 + playground/go.sum | 8 ++++++++ playground/playground.go | 2 +- 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/playground/calendar.go b/playground/calendar.go index c1146bc..9dd1074 100644 --- a/playground/calendar.go +++ b/playground/calendar.go @@ -1,6 +1,24 @@ // from chapter 10 package main -func calendar() { +import ( + "fmt" + "git.linuxhg.com/Go_Training/calendar" +) +func companyCalendar() { + event := calendar.Event{} + err := event.SetTitle("Mom's Birthday") + Error(err) + err = event.SetYear(2019) + Error(err) + err = event.SetMonth(5) + Error(err) + err = event.SetDay(27) + Error(err) + + fmt.Println(event.Title()) + fmt.Println(event.Year()) + fmt.Println(event.Month()) + fmt.Println(event.Day()) } diff --git a/playground/fuel.go b/playground/fuel.go index d365b04..7ba9eae 100644 --- a/playground/fuel.go +++ b/playground/fuel.go @@ -5,9 +5,23 @@ package main import "fmt" type Liters float64 + +func (l Liters) String() string { + return fmt.Sprintf("%0.2f L", l) +} + type Gallons float64 + +func (g Gallons) String() string { + return fmt.Sprintf("%0.2f gal", g) +} + type Milliliters float64 +func (m Milliliters) String() string { + return fmt.Sprintf("%0.2f mL", m) +} + func (l Liters) ToGallons() Gallons { return Gallons(l * 0.264) } @@ -46,4 +60,7 @@ func fuel() { milk := Gallons(2) fmt.Printf("%0.0f gallons equals %0.3f liters\n", milk, milk.ToLiters()) fmt.Printf("%0.0f gallons equals %0.3f milliliters\n", milk, milk.ToMilliliters()) + fmt.Println(Gallons(12.09285934)) + fmt.Println(Liters(12.09285934)) + fmt.Println(Milliliters(12.09285934)) } diff --git a/playground/go.mod b/playground/go.mod index a882925..1261c6f 100644 --- a/playground/go.mod +++ b/playground/go.mod @@ -13,6 +13,7 @@ require ( ) require ( + git.linuxhg.com/Go_Training/calendar v0.0.0-20240131153240-372e0ebc267d // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect diff --git a/playground/go.sum b/playground/go.sum index 7a1f2df..2cded96 100644 --- a/playground/go.sum +++ b/playground/go.sum @@ -1,3 +1,11 @@ +git.linuxhg.com/Go_Training/calendar v0.0.0-20240131021259-9a867797a789 h1:NjOZBosOrGRV87iw30jOyH8UNKv7bVNxtix+BguskVA= +git.linuxhg.com/Go_Training/calendar v0.0.0-20240131021259-9a867797a789/go.mod h1:E6GYPXO26PAOFhtrQ3d9K+yG0j6e4nFORZT5zlD7HOc= +git.linuxhg.com/Go_Training/calendar v0.0.0-20240131145407-3e70d7233820 h1:/n9lYFbddduk4UoGW0Jh12synMzF02ciC3gCkrqph5g= +git.linuxhg.com/Go_Training/calendar v0.0.0-20240131145407-3e70d7233820/go.mod h1:E6GYPXO26PAOFhtrQ3d9K+yG0j6e4nFORZT5zlD7HOc= +git.linuxhg.com/Go_Training/calendar v0.0.0-20240131150458-66340adc88a8 h1:UTF7JbrCemR61hRKderfV3Au3/0CFDIIefp70YalEww= +git.linuxhg.com/Go_Training/calendar v0.0.0-20240131150458-66340adc88a8/go.mod h1:E6GYPXO26PAOFhtrQ3d9K+yG0j6e4nFORZT5zlD7HOc= +git.linuxhg.com/Go_Training/calendar v0.0.0-20240131153240-372e0ebc267d h1:wKAe1v8k2qmtJUo/FgE2xqdLRNN31u01bT9/FQGr0MI= +git.linuxhg.com/Go_Training/calendar v0.0.0-20240131153240-372e0ebc267d/go.mod h1:E6GYPXO26PAOFhtrQ3d9K+yG0j6e4nFORZT5zlD7HOc= git.linuxhg.com/Go_Training/datafile v0.0.0-20240111160218-6989e96515a9 h1:jjPk3X9lZ6bZhsjBvEJUGyqfNalUDG0Lt5UvaPrKFtM= git.linuxhg.com/Go_Training/datafile v0.0.0-20240111160218-6989e96515a9/go.mod h1:iRnsnz7UZZtIhCX3KTblxBxtEuvPZ8MMi5GDWGIt+dw= git.linuxhg.com/Go_Training/keyboard v0.0.0-20240111160241-d208f095efce h1:S9raWDpQtH3at5D4Bm0bfnvPd3ATGGMuZ8eQMrLddFM= diff --git a/playground/playground.go b/playground/playground.go index 05c4b74..ff9e980 100644 --- a/playground/playground.go +++ b/playground/playground.go @@ -113,7 +113,7 @@ func main() { { name: "Calendar", launchFunction: func() { - calendar() + companyCalendar() }, }, }