Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please do in Java! I'm trying to learn so please put comments and explain! Input and Nested If Statements and Functions and input validation. This
Please do in Java! I'm trying to learn so please put comments and explain!
Input and Nested If Statements and Functions and input validation. This assignment is more exercise with conditional statements and code to make your program more robust. It builds on what you learned in the previous assignment in that you must now use else conditions and conditional blocks. This assignment should help you remember how to use if, else, blocks, and nested if statements in case you need a refresher. The exercise is designed in a special way to show you how you should write large programs by adding a little bit at a time. Please do these steps one at a time. The practice you will follow is called "refactoring." - Start by creating a function to get a character from user imput. - Name that function, getFirstnameChar steplo. - To show your work increments, implement each step as a separate function, called getFirstnameChar_step2(), getFirstnameChar_step3(), getFirstnameChar_step4() and getFirstnameChar_step5(). Each time, copy the code from the previous step, and then add the new modifications to the new function. - Use your First Name in the function names. - Be aware that you will not always be adding to the end of the new function, and may even have to rearrange the order of the previous pieces, in order to satisfy the new expectations presented in one or more of the steps. - To test your code, call the function for whichever step you are working on from main(). step1. Write the code that prompts the user to enter a character between ' c ' and ' o ' (including ' c and ' o '), reads the character using Scanner, and then prints the character that user entered in a statement that begins with "You entered a x".. (where x is the character you cntered) step2. Add more code or modify your code so that if the user enters a character that is less than " e or greater than o, , it prints out "The character you entered is not between ' e ' and ' o." Otherwise, and only if the character is between ' e ' and ' o ', it prints the statement as before. step3. Add more code or modify your code so that if the user enters the characters " e,, "i' or " o " "You entered an ....." instead of "You entered a ...". Note if user entered " i, you print "You entered an i, But if user entered k, you print " You entered a k step4. Add more code or modify your code so that if the user enters something that is not a character, i.e. includes numbers, your program does not print any of the above lines, but instead prints out "Hellooo! Your input could not be read as a character. prints out "Hellooo! Your input could not be read as a character. Please Get a Programming Life!". Again, note that it doesn't make sense to test something to see if it is between ' e ' and 'o' if it isn't even a character. So sequence your tests in a logical order of ruling out the various cases. Step5. This is the final step Add more code or modify your code so that if the user enters something invalid or a character not between ' e ' and ' o ' print invalid input and keep asking the user to input a character until a valid character between ' e ' and ' o ' is entered and then prints out the correct response. Each step should be developed on the previous step. Include comments in your code to explain what each of the 'if' statements is testing. Create a Project and Class called Refactoring. In the main finally comment out the calls to step1, step 2 , step3 and step4 as you have already tested these. Do not comment out using //. But comment out each function using /../ So the only live code is the call to step5. But all the five methods should be provided in the file. Zip the whole project in a single zip file and submit the zip file Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started