Welcome in this section, we'll start with a challenge, so you'll use everything you have learned so
far and you cannot create a digital clock that runs entirely on the comment line.
First of all, let me show you what the final program is going to look like, I'm just going to run
the program.
As you can see, the clock is being updated every second and it has this cool effect, I mean, the
separators are blinking every two seconds.
Let me tell you how this works.
So every second the program clears the command line screen and redraws the clock again and again in
the same position.
OK.
This creates the illusion that the clock is being animated.
I can quit from this program only by killing it because it runs in an infinite loop so it never quits.
So I'm going to press control key is to terminate it.
All right, let's talk a little bit about how we can create this program by yourself.
First of all, you would need to create an array for each digit so there will be 10 arrays for each
digit.
So how can you create these digits using arrays?
Let me show you.
For example, let's take a look at these digits in detail, these digits is actually an array with five
string elements.
These yellow lines represent the areas elements I know there are six lines, but think of them as areas.
So there are five elements in this area.
So the first element contains the first line and the second element contains the second line, and it
goes like this, you need to put each digit into its own array variable.
Let me show you.
Like this, as you can see, I created a new string array with five elements, then I put each line
of the digit in an array variable named zero, you would need to create variables like this for each
digit.
OK.
OK, let's get back to the digits.
After creating the digits from zero to nine, then you would need to create a multidimensional array
such as this one in this area, you're going to store the digits.
These red lines represent the elements of these digits array.
As you can see, there are 10 elements.
These yellow lines represent the elements of the inner arrays.
So each inner element is actually a digital era that you saw just before.
OK, so you can use these digits and then you can create the clock for the current time.
To do that, you would need to create a clock array and then you would need to populate it using these
digits.
I'm going to show you what the clock array looks like next.
So it contains eight placeholders for each column.
Right.
Let me show you what this looks like as an array.
So the clock is actually a multidimensional array with eight elements.
It contains eight placeholders, and each placeholder is a string array with five string elements.
Red lines represent the placeholder arrays.
And the yellow lines represent the elements of each placeholder array.
There are also two separate air currents, a separate there is also an array, just like a digital,
a separator or a digit, I call both of them placeholders.
There are no difference between them is because they are the same type of arrays.
Depending on the current time, you would need to update the clock.
As I said, you can get the digits from the digits array, then you can copy the digits into this clock.
After you copied the placeholders, you can use this clock array to print the clock.
So how can you get the current time?
As you know, you can get the current time using the time that now method and through that you can get
the current hour, minute and second by using these methods that you can see here.
You would also need to wrap your coat in an infinite loop, this way you'll be able to update the clock
until the user quits the program.
Of course, running your court in an infinite loop will consume unnecessary CPU resources, you would
need to slow it down so you can use the time that sleep function to sleep for one second.
At the end of every loop, you can find the link to this function in the resources, by the way, it
just takes the time that duration value and stops the world for the given time duration.
OK.
OK, now let's talk about how to clear the screen.
Just before entering the infinite loop, you would need to clear the screen once after that, you need
to move the cursor to the top left position of the screen.
By doing so, you'll be able to draw the clock on a clean screen every second.
Don't worry, I'll I've explained everything in the challenge documentation or in the card.
You can find it in the resources of this lecture as a link.
OK, let's talk a little bit about the worry of the general algorithm for this challenge, first, create
the digits from zero to nine.
They all will be erased.
That clear the screen once and for all before the infinite loop and after that create an infinite loop.
In this loop, you'll draw the clock continuously to the screen inside the loop, move the cursor to
the top left position of the screen.
Doing so will allow you to recreate the clock on a clean screen at the same position.
Always.
And after that update, the clocker, by copying the necessary digits and the separators into it, and
after that, you need to draw the clock using the clock line by line to the screen.
And lastly, wait one second before drawing the next clock.
This loop will continue until you terminate from the program.
As I said, I explained everything about this challenge with step by step instructions in the course
of the Post story, so please check out the link in the resources of this lecture.
It will take you to the step by step challenge explanation.
All right.
That's all for now.
Trust yourself because I trust you.
You can solve this challenge.
You have all the knowledge.
See the solution, lectures them by.