Browse Source

Add exercises 1.05 - 1.13

master
T. Meissner 4 years ago
parent
commit
a84c706529
9 changed files with 196 additions and 0 deletions
  1. +17
    -0
      chapter_01/exercise_1.05/main.go
  2. +21
    -0
      chapter_01/exercise_1.06/main.go
  3. +19
    -0
      chapter_01/exercise_1.07/main.go
  4. +12
    -0
      chapter_01/exercise_1.08/main.go
  5. +39
    -0
      chapter_01/exercise_1.09/main.go
  6. +22
    -0
      chapter_01/exercise_1.10/main.go
  7. +15
    -0
      chapter_01/exercise_1.11/main.go
  8. +29
    -0
      chapter_01/exercise_1.12/main.go
  9. +22
    -0
      chapter_01/exercise_1.13/main.go

+ 17
- 0
chapter_01/exercise_1.05/main.go View File

@ -0,0 +1,17 @@
package main
import (
"fmt"
"time"
)
func main() {
Debug := false
LogLevel := "info"
startUpTime := time.Now()
fmt.Println(Debug, LogLevel, startUpTime)
}

+ 21
- 0
chapter_01/exercise_1.06/main.go View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
"time"
)
func getConfig() (bool, string, time.Time) {
return false, "info", time.Now()
}
func main() {
Debug, LogLevel, startUpTime := getConfig()
fmt.Println(Debug, LogLevel, startUpTime)
}

+ 19
- 0
chapter_01/exercise_1.07/main.go View File

@ -0,0 +1,19 @@
package main
import "fmt"
var defaultOffset = 10
func main() {
offset := 5
fmt.Println(offset)
offset = 10
fmt.Println(offset)
offset = offset + defaultOffset
fmt.Println(offset)
}

+ 12
- 0
chapter_01/exercise_1.08/main.go View File

@ -0,0 +1,12 @@
package main
import "fmt"
func main() {
query, limit, offset := "bat", 10, 0
query, limit, offset = "ball", offset, 20
fmt.Println(query, limit, offset)
}

+ 39
- 0
chapter_01/exercise_1.09/main.go View File

@ -0,0 +1,39 @@
package main
import "fmt"
func main() {
// Main course
var total float64 = 2 * 13
fmt.Println("Sub:", total)
// Drinks
total = total + (4 * 2.25)
fmt.Println("Sub:", total)
// Discount
total = total - 5
fmt.Println("Sub:", total)
// 10% Tip
tip := total * 0.1
fmt.Println("Tip:", tip)
total = total + tip
fmt.Println("Total:", total)
// Split bill
split := total / 2
fmt.Println("Split:", split)
// Reward every 5th visit
visitCount := 24
visitCount = visitCount + 1
remainder := visitCount % 5
if remainder == 0 {
fmt.Println("With this visit, you've earned a reward.")
}
}

+ 22
- 0
chapter_01/exercise_1.10/main.go View File

@ -0,0 +1,22 @@
package main
import "fmt"
func main() {
count := 5
count += 5
fmt.Println(count)
count++
fmt.Println(count)
count--
fmt.Println(count)
count -= 5
fmt.Println(count)
name := "John"
name += " Smith"
fmt.Println(name)
}

+ 15
- 0
chapter_01/exercise_1.11/main.go View File

@ -0,0 +1,15 @@
package main
import "fmt"
func main() {
visits := 15
fmt.Println("First visit :", visits == 1)
fmt.Println("Return visit :", visits != 1)
fmt.Println("Silver member :", visits >= 10 && visits < 21)
fmt.Println("Gold member :", visits > 20 && visits <= 30)
fmt.Println("Platinum member:", visits > 30)
}

+ 29
- 0
chapter_01/exercise_1.12/main.go View File

@ -0,0 +1,29 @@
package main
import (
"fmt"
"time"
)
func main() {
var count int
fmt.Printf("Count: %#v \n", count)
var discount float64
fmt.Printf("Discount: %#v \n", discount)
var debug bool
fmt.Printf("Debug: %#v \n", debug)
var msg string
fmt.Printf("Msg: %#v \n", msg)
var emails []string
fmt.Printf("eMails: %#v \n", emails)
var startTime time.Time
fmt.Printf("Start: %#v \n", startTime)
}

+ 22
- 0
chapter_01/exercise_1.13/main.go View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"time"
)
func main() {
var count1 *int
count2 := new(int)
countTemp :=5
count3 := &countTemp
t := &time.Time{}
fmt.Printf("count1: %#v\n", count1)
fmt.Printf("count2: %#v\n", count2)
fmt.Printf("count3: %#v\n", count3)
fmt.Printf("time : %#v\n", t)
}

Loading…
Cancel
Save