My Plan
For our final evaluation we were given a programming challenge where we had to make a program that prompts the user for a word and determines the number of vowels in the word. The program should verify that the entry is a word meaning it contains letters only, and give the user the option of continuing or not before ending. Some examples of this is:
Input Expected Results
Aeiou Aeiou has 5 vowels.
Appl3 Invalid
cake Cake has 2 vowels.
Windo3w Invalid
dfsougIGV Dfsougigv has 3 vowels.
jhviWH Jhviwh has 1 vowel.
Kjfb;kf Invalid
kjkjklkk Kjkjklkk has no vowels.
My plan to make this program work and achieve its function is to:
- Name and define variables - few of my variables will be global so I can access then from all my methods
My Variables:
userWord - to take the input of user
name - to take the name of the user
continuation - to ask the user if they want to continue with the program or not
comment - to ask for the user to input a comment if they continued
- I would be using methodns, method calls, backgrounds and animation. All of these will go in the main method.
My method names:
nameOfUser (); - this will be a functional method (my first method)
inputOfUser (name); - this will be a procedural method (my second method)
-My first method will be introducing the project and asking for the users' name
-My second method will be taking a word from the user. Also it will have cases for the vowels in lowercase and the vowels in uppercase
-The second method will contain a if statement if (userWord.matches ("[a-zA-Z]")) , within the if statement there will be a for-loop, so if the condition is true, the program will enter into a for loop and within the for-loop, there will be a switch which will hold the cases. After the cases have been assigned there is a break to end the for loop.
- After the second method there will be an else statement which will execute if the condition is not met. This will help give the user the "invalid" sentence if they enter a word that does not contain only LETTERS. It will also contain the name of the second method so it can loop it back and the user can try again
- After this there will be another if statement which will have the condition if (continuation == 1), this will help me ask the user if they want to continue or not. If they say no, the program will end and if they say yes, it will go into the else if statement and ask the user to put a comment.
Input Expected Results
Aeiou Aeiou has 5 vowels.
Appl3 Invalid
cake Cake has 2 vowels.
Windo3w Invalid
dfsougIGV Dfsougigv has 3 vowels.
jhviWH Jhviwh has 1 vowel.
Kjfb;kf Invalid
kjkjklkk Kjkjklkk has no vowels.
My plan to make this program work and achieve its function is to:
- Name and define variables - few of my variables will be global so I can access then from all my methods
My Variables:
userWord - to take the input of user
name - to take the name of the user
continuation - to ask the user if they want to continue with the program or not
comment - to ask for the user to input a comment if they continued
- I would be using methodns, method calls, backgrounds and animation. All of these will go in the main method.
My method names:
nameOfUser (); - this will be a functional method (my first method)
inputOfUser (name); - this will be a procedural method (my second method)
-My first method will be introducing the project and asking for the users' name
-My second method will be taking a word from the user. Also it will have cases for the vowels in lowercase and the vowels in uppercase
-The second method will contain a if statement if (userWord.matches ("[a-zA-Z]")) , within the if statement there will be a for-loop, so if the condition is true, the program will enter into a for loop and within the for-loop, there will be a switch which will hold the cases. After the cases have been assigned there is a break to end the for loop.
- After the second method there will be an else statement which will execute if the condition is not met. This will help give the user the "invalid" sentence if they enter a word that does not contain only LETTERS. It will also contain the name of the second method so it can loop it back and the user can try again
- After this there will be another if statement which will have the condition if (continuation == 1), this will help me ask the user if they want to continue or not. If they say no, the program will end and if they say yes, it will go into the else if statement and ask the user to put a comment.
Reflection
When doing this assignment, I ran into some problems which I had to deal with quickly if I wanted to get the project done and hand it in on time. A problem I faced was to find a way to count the number of vowels. After spending some time thinking about the question, I figured out that I should use cases for the vowels and have the cases in a switch. Put that in a for loop which is already in a if statement. All of this is in the method of inputOfUser. Since I also included the counter, it allowed my program to recognize the amount of vowels in the word inputted by the user. After modifying my program I was able to solve the problem I faced.
Another problem I ran into was to figure out a way to put my error message if the word inputted by the user did not contain only letters. I thought at first that a for loop in a separate method would do the trick, however, this was not the case. Then thinking about it even more got me the idea to have an else statement outside the method that contained the if statement. This way if the conditions aren't met then the program will run what ever is with the else statement which would be the error message. It also contains the method call so the user can input a correct word on their next try.
There were problems that I faced however there were also positives. The positives about my program were that I was able to figure out a way to use if statement, for-loop statement and lastly the cases in the switch. These were topics that I sometimes had difficulty with, but reviewing them from my notes and previous programs helped me better enhance my program .
Another problem I ran into was to figure out a way to put my error message if the word inputted by the user did not contain only letters. I thought at first that a for loop in a separate method would do the trick, however, this was not the case. Then thinking about it even more got me the idea to have an else statement outside the method that contained the if statement. This way if the conditions aren't met then the program will run what ever is with the else statement which would be the error message. It also contains the method call so the user can input a correct word on their next try.
There were problems that I faced however there were also positives. The positives about my program were that I was able to figure out a way to use if statement, for-loop statement and lastly the cases in the switch. These were topics that I sometimes had difficulty with, but reviewing them from my notes and previous programs helped me better enhance my program .