Java program | Computer Science homework help



Input and Nested If Statements and Functions

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 in integer from user input. Name that function, getUserValue_step1(). To show your work increments, implement each step as a separate function, called getUserValue_step2(), getUserValue_step3(), getUserValue_setp4() and getUserValue_setp5(). Each time, copy the code from the previous step, and then add the new modifications to the new function. 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 an integer between 1 and 20 (including 1 and 20), reads the value using Scanner, and then prints the value that they entered in a statement that begins with “You entered a “. 

step2. Add more code or modify your code so that if the user enters a value that is less than 1 or greater than 20, it prints out “The value you entered is not between 1 and 20.” Otherwise, and only if the value is between 1 and 20, it prints the statement as before. 

step3. Add more code or modify your code so that if the user enters the values 8, 11, or 18, the statement that is printed is “You entered an” instead of “You entered a”. Note in putting these things in a particular order, that testing for 8, 11, and 18 makes more sense if you already know that the number is between 1 and 20. 

step4. Add more code or modify your code so that if the user enters something that is not a number, i.e. includes letters, your program does not print any of the above lines, but instead prints out “Idiot! Your input could not be read as a number. Get a life!”. Again, note that it doesn’t make sense to test something to see if it is between 1 and 20 if it isn’t even a number. So sequence your tests in a logical order of ruling out the various cases. 

Step5. Add more code or modify your code so that if the user enters something invalid or an integer not between 1 and 20 print invalid input and keep asking the user to input a number until a valid number between 1 and 20 is entered and then prints out the correct response. 

Include comments in your code to explain what each of the ‘if’ statements is testing. 

Zip the java file in a single zip file and submit the zip file. 

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with Australia Assessments
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
The paper was beautifully written and the ppt slide exceeded my expectations. Thank you so much for assisting me with a last minute assignment.
Customer 452455, May 9th, 2023
Very good job.
Customer 456821, April 8th, 2022
Well-written content. The writer follows instructions to the letter upon revisions.
Customer 463679, December 13th, 2022
Good job!
Customer 463469, October 29th, 2022
Satisfactory work.
Customer 456821, April 14th, 2022
Business Studies
Excellent as always!
Customer 454647, June 26th, 2020
Business and administrative studies
Good work.
Customer 458115, May 10th, 2022
This submission was excellently done. Looking foward to your future contribution.
Customer 463463, December 12th, 2022
Public Health
Good work
Customer 452657, February 14th, 2020
Several grammar issues identified.
Customer 462821, April 6th, 2022
Religious studies
Thank you this was supper
Customer 452763, March 17th, 2020
Did an excellent job on the paper!
Customer 463095, June 22nd, 2022
Customer reviews in total
Current satisfaction rate
3 pages
Average paper length
Customers referred by a friend
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat