-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
151 lines (124 loc) · 5.76 KB
/
Program.cs
File metadata and controls
151 lines (124 loc) · 5.76 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// FINAL C# PROJECT - TASK MANAGER
// The 'using' directive allows all the names in a namespace to be used without the namespace-name as an explicit qualifier
using System;
using System.Collections.Generic;
namespace MyApp
{
class Program
{
// MAIN METHOD
static void Main(string[] args)
{
string response;
int parsedResponse;
var menuList = new List<string>(){ "1. Add a task", "2. Remove a task", "3. Mark a task complete", "4. List the tasks", "", "What would you like to do?" };
// 'taskList' and 'completeList' run with parallel indices to keep track if a task is complete
var taskList = new List<string>();
var completeList = new List<string>();
// BIG FOR LOOP (arbitrarily large loop to keep the program running)
for (int i = 0; i < 1000000; i++)
{
// DISPLAY THE MENU LOOP
void displayMenu()
{
Console.Clear();
for (int j = 0; j < menuList.Count; j++)
{
Console.WriteLine(menuList[j]);
}
// WAIT FOR SELECTION
response = Console.ReadLine();
// 'if' STATEMENT TREE TO DIRECT TO PROPER METHODS
if (response == "1")
{ addTask(); }
else if (response == "2")
{ removeTask(); }
else if (response == "3")
{ completeTask(); }
else if (response == "4")
{ listTask(); }
}
displayMenu();
// //////////// METHODS ////////////
// 1. ADD A TASK METHOD
void addTask()
{
Console.Clear();
Console.WriteLine("Please add a task:");
response = Console.ReadLine();
// add item to 'taskList' and 'completeList'
taskList.Add(response);
completeList.Add("");
}
// 2. REMOVE A TASK METHOD
void removeTask()
{
// if there is nothing in the list
if (taskList.Count == 0)
{
Console.WriteLine("-- There are currently NO tasks in your list --");
Console.WriteLine("");
Console.WriteLine("Please hit 'Enter' to return to Main Menu");
}
Console.Clear();
Console.WriteLine("Here is your Current Task List:");
Console.WriteLine("");
for (int j = 0; j < taskList.Count; j++)
{
Console.WriteLine((j+1) + ". " + taskList[j] + " " + completeList[j]);
}
Console.WriteLine("");
Console.WriteLine("Please enter the number of the task you would like removed");
// prevent 'index' < 0 program crash
if (taskList.Count != 0)
{
response = Console.ReadLine();
parsedResponse = Int32.Parse(response);
taskList.Remove(taskList[(parsedResponse-1)]);
completeList.Remove(completeList[(parsedResponse-1)]);
}
}
// 3. MARK A TASK COMPLETE METHOD
void completeTask()
{
Console.Clear();
Console.WriteLine("Here is your Current Task List:");
Console.WriteLine("");
// if there is nothing in the list
if (taskList.Count == 0)
{
Console.WriteLine("-- There are currently NO tasks in your list --");
}
for (int j = 0; j < taskList.Count; j++)
{
Console.WriteLine((j+1) + ". " + taskList[j] + " " + completeList[j]);
}
Console.WriteLine("");
Console.WriteLine("Please enter the number of the task that you have completed");
response = Console.ReadLine();
parsedResponse = Int32.Parse(response);
completeList[(parsedResponse-1)] = ("(COMPLETE)");
}
// 4. LIST THE TASKS METHOD
void listTask()
{
Console.Clear();
Console.WriteLine("Here is your Current Task List:");
Console.WriteLine("");
// if there is nothing in the list
if (taskList.Count == 0)
{
Console.WriteLine("-- There are currently NO tasks in your list --");
}
for (int j = 0; j < taskList.Count; j++)
{
Console.WriteLine((j+1) + ". " + taskList[j] + " " + completeList[j]);
}
Console.WriteLine("");
Console.WriteLine("Please hit 'Enter' to return to Main Menu");
response = Console.ReadLine();
}
}
}
}
}