Chpt5_Project

Write a Java program that generates 100 random numbers in the range of 0-100 and counts how many are equal to or greater than a value entered by the user.

Inputs: Prompt the user for the value to test against. This value must be between 30 and 70. If the value is out of range then let the user reenter the value until it is with the range.

Outputs: The output will be all the number of random numbers equal to or larger than the number input by the user.

Step 1. Create an algorithm (either flowchart or pseudocode) that you will use to write the program. Place the algorithm in a Word document.
Step 2. Code the program to prompt the user for a value between 30 and 70 (30 < value < 70). The value must the checked to ensure it is in the required range. If the user’s value is out of range then they are prompted to reenter until the value is in range. Use a while or do-while loop to keep prompting until the value is within the range. Next, use a for loop to generate 100 random variables between 0 and 100 and compare each random number to the value entered by the user. If value < random number then then increase the count by 1. Lastly, print out the number of times the random number is larger than the value entered by the user. Step 3. Test your program and it should display the number of random numbers greater than or equal to the user input value. Use the test data in the example below by entering 80 first, which is out of range, then enter 50. Note: the number of random variables greater than 50 will vary because the user value is being compared to random numbers, and those random numbers change each time the program runs. Use the Snip It tool in Windows or a similar tool on the Mac to cut and paste the Eclipse Console output window into the same Word document as the algorithm in Step 1. Below is an example output. Note: your output will be different because random numbers are involved.

×
New Download