-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (54 loc) · 1.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"time"
)
type Task struct {
ID int
Title string
Assignee string
Deadline time.Time
Completed bool
}
type Scheduler struct {
Tasks []Task
}
func (s *Scheduler) AddTask(title, assignee string, deadline time.Time) {
taskID := len(s.Tasks) + 1
task := Task{
ID: taskID,
Title: title,
Assignee: assignee,
Deadline: deadline,
Completed: false,
}
s.Tasks = append(s.Tasks, task)
fmt.Println("Task added:", task)
}
func (s *Scheduler) CompleteTask(taskID int) {
for i, task := range s.Tasks {
if task.ID == taskID {
s.Tasks[i].Completed = true
fmt.Println("Task completed:", task)
return
}
}
fmt.Println("Task not found")
}
func main() {
scheduler := Scheduler{}
scheduler.AddTask("Design UI", "Alice", time.Now().Add(48*time.Hour))
scheduler.AddTask("Write API Docs", "Bob", time.Now().Add(72*time.Hour))
scheduler.AddTask("Test Feature", "Charlie", time.Now().Add(96*time.Hour))
fmt.Println("Current Tasks:")
for _, task := range scheduler.Tasks {
fmt.Printf("ID: %d | Title: %s | Assignee: %s | Deadline: %s | Completed: %v\n",
task.ID, task.Title, task.Assignee, task.Deadline.Format("2006-01-02 15:04:05"), task.Completed)
}
scheduler.CompleteTask(2)
fmt.Println("\nUpdated Tasks:")
for _, task := range scheduler.Tasks {
fmt.Printf("ID: %d | Title: %s | Assignee: %s | Deadline: %s | Completed: %v\n",
task.ID, task.Title, task.Assignee, task.Deadline.Format("2006-01-02 15:04:05"), task.Completed)
}
}