Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 input.
Name that function, firstnameGetCharstep
To show your work increments, implement each step as a separate function, called
firstnameGetCharstep firstnameGetCharstep firstnameGetCharstep and
firstnameGetCharstep Each time, copy the code from the previous step, and then add
the new modifications to the new function.
Use your FirstName 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
step Write the code that prompts the user to enter an upper case character between I and U
including I and U reads the character using Scanner, and then prints the character that user
entered in a statement that begins with "You entered a Xwhere X is the character you entered
step Add more code or modify your code so that if the user enters an upper case character that
is less than I or greater than U it prints out "The character you entered is not between I and
U Otherwise, and only if the character is between I and U it prints the statement as before.
Use the ternary conditional operator to do the print.
step Add more code or modify your code so that if the user enters the characters IO or U
"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
step Add more code or modify your code so that if the user enters something that is not a
character, ie includes numbers or lower case characters, your program does not print any of the
above lines, but instead prints out "Hellooo! Your input could not be read as an Upper case
character. Please Get a Programming Life!". Again, note that it doesnt make sense to test
something to see if it is between I and U if it isnt even a character. So sequence your tests in
a logical order of ruling out the various cases.
step 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 I and U print invalid input and keep asking the
user to input a character until a valid character between I and U 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
step step step and step 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 step But
all the five methods should be provided in the 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