00:01
In this promer astoriter program that allows the user to input a character in a string, and then we return how many times this character appears in the string.
00:11
So i called this class char count.
00:15
Here's the constructor.
00:17
The constructor is empty.
00:19
The reason for that is because we really do all of our work in the method here.
00:24
But of course, there are several ways you could write this to where the constructor would of stuff.
00:32
Anyway, this method is called git count, and it's what does the, i guess, computation in this program.
00:40
It returns an integer, right? and it takes into parameters.
00:47
So char c and string s.
00:51
And essentially, once we get into this function, we're initializing this variable count, and then we're hopping right into a four loop.
01:00
And this four loop is going to keep iterating until we get to the length of our string s here.
01:10
And at each iteration, we check and we see if the character at our index of our string s is equal to c, which c is the char, that was our parameter in our function, right? then we increase our variable count by one.
01:33
And once we've iterated through the entire length of the string, checked each character, then we returned the final count at the end.
01:45
So how did we actually implement this? so i just have a main function here to demonstrate that.
01:53
So first we create a new char count object, right? new object for our class.
02:02
And then we also have to initialize a scanner variable because we are getting user input.
02:09
And then we print out, enter some text or something of similar nature, and then collect whatever the user has inputted by doing scan...