Write a method called randomInRange that takes in two numbers representing a range. Print an error message and return zero if the second parameter is less than the first. Otherwise, the method should return a randomly generated integer in that range (inclusive). You may assume that the class has a static Random object called generator already declared and instantiated.

What will be an ideal response?


```
public int randomInRange(int a, int b) {
if(b < a) {
System.out.println("Error, invalid range!");
return 0;
}
return generator.nextInt(b – a + 1) + a;
}
```

Computer Science & Information Technology

You might also like to view...

Given the (incomplete) class template below, complete the template and show how to implement the function member whose declaration in class template below is: void f(T x); Hint: What the function does is immaterial. We are only interested in the details of the header in the implementation. Use the following for the function body if you wish.

What will be an ideal response? ``` { //whatever f does } // template class Problem: template class Problem { public: . . . void f( T x ); private: int x; }; ```

Computer Science & Information Technology

Assign to ptr the location of the last occurrence of c in s1.

What will be an ideal response?

Computer Science & Information Technology

The Backup and Restore applet automatically creates a subfolder structure within the computer folder that contains a subfolder for each _______ you've performed

a. Restore b. Backup c. Change d. Scan

Computer Science & Information Technology

Which of the following is the component of the processor that performs arithmetic, comparison, and other operations?

A. machine unit B. control unit C. ALU D. CPU

Computer Science & Information Technology