Originally Posted by
xionyus
I get the fact that it's an easy concept. The lab my teacher wanted us to construct is a random phone number generator.
The area code has to be 218, 312, or 731, it can't be anything else. He told us that we can use Math.random() for this method, but I cannot think of a way how the computer can generate those numbers unless there's an if statement. Any help? I'll post my code if needed. I just don't know the concept I am supposed to use.
First, create your Random object
You have three options, and you need to randomly choose one.
int areaCodeType = gen.nextInt(3);
Then, based on that randomly generated number, choose your area code
int areaCode = -1;
switch(areaCodeType)
{
case 0:
areaCode = 218;
break;
case 1:
areaCode = 312;
break;
case 2:
areaCode = 731;
break;
}