Question: DO ALL AS ONE PROGRAM PLEAS. Exercise 1 (15 Points) In BlueJ, create a new project called Exec3 Create a class in that project called

DO ALL AS ONE PROGRAM PLEAS.

Exercise 1 (15 Points)

In BlueJ, create a new project called Exec3 Create a class in that project called LotsaLoops Write a static method in that class called makeRand In makeRand, create a Random object named gen Set an integer variable num to a random value in the range 0 to 99 (INCLUSIVE), then print it as follows: From 0 to 99: xxx

Compile the code and run the method. Run it several times. Exercise 2 (10 Points)

Compute and print values in the following ranges (INCLUSIVE) -- do the computation right in the println statement. Remember, the general form is gen.nextInt(max - min + 1) + min; From 1 to 20: xxx

From 5 to 10: xxx

From 700 to 800: xxx

From 12 to 47: xxx

From -10 to 30: xxx

Exercise 3 (15 Points)

Generate a random number in the range 1 to 1000 and store it in a variable named myVal Then use a while loop to check to see if myVal is outside of the "good" range 400 to 500 (see if it's less than 400 or greater than 500) If it is, print the bad value and generate another value in the range 1 to 1000. Stay in the loop until you get a value in the good range (400 500) Print the good value after you fall out of the loop. Run the method multiple times. Exercise 4 (10 Points)

Now write a for loop that executes 20 times. Use a control variable called count that runs from 1 to 20. Each time through the loop, generate and print a random number in the range 50 to 100. An output example should look similar to: 83

70

55

84

61

etc.

Exercise 5 (10 Points)

Now modify the body of that for loop so that the output shows the value of the control variable for each value printed: 1: 83

2: 70

3: 55

4: 84

5: 61

etc.

Exercise 6 (10 Points)

Now create a new method called moreForLoops (static, no parameters, no return value). In this method, write a for loop that prints the integers from 40 to 50 all on the same line separated by a comma and a space: 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,

For now, it's OK to print a comma after the last value. How many times does the loop body execute? Exercise 7 (15 Points)

Copy and paste the for loop from your previous exercise. Add a blank println statement between the two to start the output of the second on a new line. This time, instead of printing the comma and space after each number, use an if statement in the body of the loop to determine if they should be printed. Don't print the comma and space after the last value: 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50

Exercise 8 (15 Points)

Add another blank println statement to start further output on a new line. Now use a for loop to compute the sum of the integers from 70 to 362. Each time through the loop, add the value to a running sum (declare sum and initialize it to 0 before the loop). Print the results after the loop completes: The sum of the integers from 70 to 362 is xxx

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!