Looking for help with an assignment? Connect with an assignment Expert Now!

enter a range of values and then display them. 

enter a range of values and then display them. . Open UserInput.java in DrJava. The program will ask the user to enter a range of values and then display them.

Note that it includes commented out calls to the methods that you will define.

Once you’ve implemented the relevant method you can uncomment those lines to test your implementation.

Implement askForInt The new method askForInt is intended to prompt the user to enter an integer within a given range, read their response, and to continue prompting them and reading their response until it is within that range.

Implement askForInt based on the following pseudocode description (where variable values appearing in output are highlighted):

Method: int askForInt(Scanner in, String prompt, int min, int max) Returns: int,

the valid value entered by the user Parameters: Scanner in, the Scanner to read user input String prompt,

the message to prompt the user with int min, the lower bound of the allowed range int max, the upper bound of the allowed range Variables:

int value, value entered by user

Steps: 1 Display “prompt (min-max): ” on one line

2 Assign value result of in.nextInt()

3 While value < min or value > max:

3-1 | Display “Invalid value”

3-2 | Display “prompt (min-max): ” on one line

3-3 | Assign value result of in.nextInt()

4 Return value Note: Remember to use appropriate Java syntax for the while loop and logical or Add a suitable header comment to explain what this method does.

Keep the description general;

do not tailor it to suit the way it is used by the testing code in main. In the main() method remove the comment that reads in the value for the guess variable.

Compile and run the program and test it by entering -50, then 11, before trying a valid value.

Implement askForDouble Using the same pattern as above, design and implement askForDouble, and test using the percent value in main().

Hint: The changes are very slight, so copy, paste and modify.

Don’t forget to modify the header comment as well.

In the main() method remove the comment that reads in the value for the percent variable.

Compile and run the program and test it with a variety of incorrect inputs before trying a valid value.

Implement askForYesNo The Scanner’s nextBoolean() method does exactly what it claims—reads the next piece of text that is ‘true’ or ‘false’ and returns a boolean—and nothing more.

So it’s fine for providing basic interaction, especially with other programmers, but it’s not a great way for a normal user to enter a truth value.

Design and implement askForYesNo.

You can use the previous two methods as a guide but make the following key changes: Remove the min and max parameters. Knowledge of valid values will be built-in to the method.

Display the prompt followed by suitable explanatory text such as ‘(yes/no)’. Do not use nextBoolean(), since it only works with the inputs ‘true’ and ‘false’. Instead use the Scanner’s next() method to read in the next String the user enters. If the user enters “y”, “yes” or “true” (in any case) then the method should return true. If the user enters “n”, “no” or “false” (in any case) then the method should return false. If they enter any other value then display an error and prompt them again, as done in askForInt and askForDouble.

Tips: Use the String method toLowerCase() to convert the user’s input to a value suitable for comparing against the valid alternatives. (As with all String methods, it returns a copy of the modified String, it does not actually change the String on which it is called.)

You can use either an if or switch construct for checking (and converting) the user’s input.

Consider declaring two boolean variables in your method, one the value to be returned and another indicating if the current input is actually valid.

Consider using a do-while loop (and the ‘is valid’ variable suggested above) as this will reduce the amount of code you need to write. As with the previous two methods, add a method header comment containing a general description of the method’s behaviour (not a description of the example usage shown in main).

In the main() method remove the comment that reads in the value for the again variable. Compile and run the program and test it with a variety of incorrect inputs before trying a valid value. Remember that upper case or mixed case entries are valid if they match any of the six possible input values.

enter a range of values and then display them. 

Get a Quick Quote

Approximately 250 words
Total price (USD) $: 10.99

Pressed for time on your upcoming paper? We can help!

Bored with homework

Reviews from Clients who Ordered from Our Website

Client: 3425

Ive submitted over 30 assignments from this website and gotten an average of 3.8 G.P.A.

Client: 2516

Juggling school with family and work has always been hectic but this website made it easy to do my studies and work while raising my 3 year old girl.

Client: 3516

Great customer service and quality work delivered on time!

Client: 2718

Client: 7384

Client: 8291

Client: 162

Client: 827

They delivered a professional and well written Resume for me. Reccommend

Why Us?

Privacy

Your personal and payment details are safe with us. Our website uses secure encryption for all orders. We guarantee not to share your details with any third parties.

Flexible Pricing

We offer great discounts and flexible pricing tailored to your needs. Additionally, we provide offers for orders above 30 pages and returning customer.

Originality

Our Professional Team of Writers have great experience and writing techniques to provide you with Quality Non-plagiarized work.

Customer Support

Our Customer Support and Professional Team of Writers are always available to help you anytime. Our Team  of writers are also available to take care of your writing needs 24/7 Live Chat is available 24/7 

How it Works

Step1: Provide Instructions

 

Provide detailed instructions including deadline for your paper and any additional information

Step 2: Pay & Assign Writer

 

Complete payment through our safe checkout and wait for your order to be assigned to suitable writer

Final Step: Download & Review

 

Download & Review your paper. You may request revision if anything is not satisfactory and rate the writer.