Page 401 - Introduction to Programming with Java: A Problem Solving Approach
P. 401

                 c) Write a method called triangular that generates an int random number from a symmetrical dis- crete triangular distribution that goes between the int values min and max, including both of these end points. (Hint: Make two calls to the int version of the above uniform method.)
d) Write a method called exponential that generates a double random number from an exponential distribution having an expected time between random arrival events equal to averageTimeInterval. Here is the algorithm:
return ← averageTimeInterval*loge(1.0􏰀Math.random)
10. [after §9.6] In the PennyJar program, the PennyJar dot prefix is used to access PennyJar members. There are four PennyJar dot prefixes in the PennyJar class and one PennyJar dot prefix in the PennyJarDriver class. For each such prefix, is it legal to omit it?
11. [after §9.7] PetMouse program:
The program below creates a linked list of objects. The class reference variable, pets, refers to the
first object in the list, and each subsequent object contains an instance reference variable that refers to the next object, except the instance reference variable in the last object refers to null. Notice that the individual pets are anonymous objects, in that they do not have separate names. The class reference variable, pets, actually refers to the first object in the list, but conceptually it refers to all the objects in the list. Notice that we use the same word, next, for a local variable in a class method and an instance variable, because both variables are really talking about the same things, and it would be unnatural to use different terms.
1 /**************************************************************
10
public static void main(String[] args)
11
{
12
new PetMouse();
new PetMouse();
new PetMouse();
PetMouse.list();
// end main
13
14
15
16
}
17
}
// end class PetMouseDriver
9
10
11
{
2 *
3 *
4*
PetMouseDriver.java
Dean & DAeapnagoPDFEnhancer
This creates & displays a linked list of simple objects.
5
*
6
**************************************************************/
7
8
public class PetMouseDriver
9{
1
/**************************************************************
2
*
3
PetMouse.java
Dean & Dean
This creates & displays a linked list of simple objects.
**************************************************************/
import java.util.Scanner;
public class PetMouse
4*
5
*
6
7
8
*
Exercises 367




































   399   400   401   402   403