Something i had to make for class. Just thoguth i'd pass it along. Not the most elagant piece of code, but got an A+
/**
* Project Name: <Phone Number Spoofer>
* Author: <Live Wire>
* Instructor: <Some Guy>
* Purpose: <To create numbers>
* Date: <Dec 2, 2011>
* Assistance: <None>
*/
//Imports
import java.util.Random;
class M3L1T1_2
{
//Static variables
static Random rd = new Random();
public static void main(String[]args)
{
//Variable Declarations
//Operating Code
System.out.printf ("This program was written by Live Wire\n\n"+
"The random phone number generated was: %03d-%03d-%04d",numberGen(),numberGen(),numberGen());
}// end of main method
/**
* This numberGen method creates a random set number
*
* No parameters
*/
public static int numberGen()
{
int setNum = 1;
int maxVall = 800;
int minVal = 100;
int setValue = 0;
int numGen = rd.nextInt(999)+1;
while ( setNum < 3){
if (setNum == 1){
String numString = Integer.toString(numGen);
if ((numString.contains("8"))|(numString.contains("9"))){ //Separates the 8s and 9s
numGen = rd.nextInt(999)+1;
}else {
setValue = numGen;
setNum++;
}
}while (setNum == 2){ //This can produce an 8, it just takes many trials
if (numGen > 742){
numGen = rd.nextInt(999)+1;
}else {
setValue = numGen;
setNum++;
}
}while (setNum == 3) {
setValue = numGen;
setNum++;
}
}//end of while
return setValue;
}
}//end of class