-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
199 lines (194 loc) · 9.17 KB
/
Program.cs
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RunningDatabase
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Running Times");
Console.WriteLine();
Console.WriteLine("Press 't' and press ENTER to create a new track (I just need his length)");
Console.WriteLine();
Console.WriteLine("Press 'a' and press ENTER to sumbit a new time for a track");
Console.WriteLine();
Console.WriteLine("Press 'v' and press ENTER to view all your times for a track");
Console.WriteLine();
string input = Console.ReadLine();
if (input.ToUpper() == "T")
{
Console.Clear();
Console.WriteLine("Enter a name for the track:");
string name = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Enter the track's length (in kilometers, excat number)");
string trackLength = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Now, leave a note, like the location this track starts and/or leads to. (you can enter it empty)");
string note = Console.ReadLine();
int track = int.Parse(File.ReadAllText(@"count.txt"));
track = track + 1;
File.WriteAllText(@"count.txt", track.ToString());
string[] TextForTrack = new string[6];
TextForTrack[0] = $"Track name: {name}";
TextForTrack[1] = "";
TextForTrack[2] = $"Length = {trackLength} kilometers";
TextForTrack[3] = "";
TextForTrack[4] = $"Note about the track: ";
TextForTrack[5] = $"{note}";
File.WriteAllLines($@"track{track}.txt", TextForTrack);
Console.WriteLine();
Console.WriteLine("The track has been created! Press any key and ENTER to return to the main meun");
Console.ReadLine();
Console.Clear();
Main(args);
}
else if (input.ToUpper() == "A")
{
Console.Clear();
string[] trackText;
Console.WriteLine("Enter the number of the track (that you want to sumbit the run to):");
Console.WriteLine();
int tracksCount = int.Parse(File.ReadAllText("count.txt"));
for (int i = 0; i <= tracksCount; i++)
{
if (File.Exists($@"track{i}.txt"))
{
trackText = File.ReadAllLines($@"track{i}.txt");
Console.WriteLine($"{trackText[0]} (Track number {i})");
Console.WriteLine();
}
}
int input2 = int.Parse(Console.ReadLine());
for (int i = 0; i <= tracksCount; i++)
{
if (input2 == i)
{
trackText = File.ReadAllLines($@"track{i}.txt");
Console.Clear();
Console.WriteLine($"{trackText[0]}");
Console.WriteLine();
Console.WriteLine("Reminder: 1 hour = 3600 seconds, 1 minute = 60 seconds, and don't include hundreds!");
Console.WriteLine("Another reminder, there's a calculator application in your computer");
Console.WriteLine("So, for example, a run that took 1 hours and 5 minutes took:");
Console.WriteLine("3600 * 1 (hour) + 60 * 5 (minutes) = 3900 seconds. Calculate your run's seconds like that");
Console.WriteLine();
Console.WriteLine("Enter the total amount of seconds the run took:");
int newTime = int.Parse(Console.ReadLine());
int hours = 0;
int minutes = 0;
int seconds = 0;
Console.WriteLine();
Console.WriteLine("Additional notes (you can leave this empty):");
string note2 = Console.ReadLine();
if ((newTime / 3600 >= 1))
{
double remains = newTime % 3600;
double ForHours = newTime - remains;
hours = (int)ForHours / 3600;
newTime = newTime - (hours * 3600);
}
if (newTime / 60 >= 1)
{
double remains2 = newTime % 60;
double ForMinutes = newTime - remains2;
minutes = (int)ForMinutes / 60;
newTime = newTime - (minutes * 60);
}
if (newTime >= 1)
{
seconds = newTime;
}
int intialNumLines = trackText.Count() - 1;
string time = "";
if (minutes < 10 && seconds >= 10)
{
time = $"{hours}:0{minutes}:{seconds}";
}
if (seconds < 10 && minutes >= 10)
{
time = $"{hours}:{minutes}:0{seconds}";
}
if (seconds < 10 && minutes < 10)
{
time = $"{hours}:0{minutes}:0{seconds}";
}
if(seconds > 10 && minutes > 10)
{
time = $"{hours}:{minutes}:{seconds}";
}
string[] newFile = new string[intialNumLines + 7];
for (int y = 0; y <= intialNumLines; y++)
{
newFile[y] = trackText[y];
}
newFile[intialNumLines + 1] = "";
newFile[intialNumLines + 2] = "A run:";
newFile[intialNumLines + 3] = "";
newFile[intialNumLines + 4] = $"Data of sumbiting the run: {DateTime.Now}";
newFile[intialNumLines + 5] = $"Run time = {time}";
newFile[intialNumLines + 6] = $"Note: {note2}";
File.Delete($@"track{i}.txt");
File.WriteAllLines($@"track{i}.txt", newFile);
Console.WriteLine();
Console.WriteLine("The run has been sumbited!");
Console.WriteLine("You can view it by entering 'v' in the main meun and then choosing this run's track");
Console.WriteLine("Press any key to return to the main meun");
Console.ReadLine();
Console.Clear();
Main(args);
}
}
}
else if (input.ToUpper() == "V")
{
Console.Clear();
string[] trackText;
Console.WriteLine("Enter the number of the track (that you want to view your runs in it):");
Console.WriteLine();
int tracksCount = int.Parse(File.ReadAllText("count.txt"));
for (int i = 0; i <= tracksCount; i++)
{
if (File.Exists($@"track{i}.txt"))
{
trackText = File.ReadAllLines($@"track{i}.txt");
Console.WriteLine($"{trackText[0]} (Track number {i})");
Console.WriteLine();
}
}
int input2 = int.Parse(Console.ReadLine());
Console.Clear();
Console.WriteLine();
Console.WriteLine("Note: the time will be shown like this: '0:00:00'");
Console.WriteLine("So if the time is, say, '1:25:33',");
Console.WriteLine("the run's time is 1 hour and 25 minutes and 33 seconds.");
Console.WriteLine();
for (int i = 0; i <= tracksCount; i++)
{
if (input2 == i)
{
trackText = File.ReadAllLines($@"track{i}.txt");
for (int y = 0; y <= trackText.Count() - 1; y++)
{
Console.WriteLine(trackText[y]);
}
Console.WriteLine();
Console.WriteLine("Press any key to return to the main meun");
Console.ReadLine();
Console.Clear();
Main(args);
}
}
}
else
{
Console.Clear();
Main(args);
}
}
}
}