/** *Name:CreateRandomNumber.java *Author:Richard *Date:Apr-10,2006 *Version:1.0.0.0 *============================ *随机整数生成类 *============================ *Author Version Date Changes *Richard 1.0.0.2 Apr-11,2006 use EXCEPTION to instead of "if" */
public class CreateRandomNumber{
protected int r_min; protected int r_max; protected int r_num; protected int r_arr[]; protected int r_mid;
/** *construct method */ public CreateRandomNumber(){
/** *set method */ public CreateRandomNumber(int pr_min, int pr_max, int pr_num, int pr_mid){
try{ if(pr_num<0) throw new CreateRandomArrayException("ERROR: Num is less than zero!"); else if(pr_min>pr_max) throw new CreateRandomArrayException("ERROR: min is greater than max!"); else if(pr_mid<pr_min || pr_mid>pr_max) throw new CreateRandomArrayException("ERROR: mid is not between min and max!"); else{ r_min = pr_min; r_max = pr_max; r_num = pr_num; r_mid = pr_mid;
/** *print the max and min result */ public void maxAndMin(){
int max = r_arr[0]; int min = r_arr[0]; for(int i=1; i<r_num; i++){ if(r_arr[i]>max) max = r_arr[i]; if(r_arr[i]<min) min = r_arr[i]; } System.out.println("The max is :" +max); System.out.println("The min is :" +min); }
/** *count how many numbers are greater than r_mid */ public int countNum(){
//==========End Class CreateRandomNumber==========
/** *Class Name:CreateRandomArrayException *===================================== *use this class to process the exception in create random array */ class CreateRandomArrayException extends Exception{
/** *construct method */ public CreateRandomArrayException(String msg){
super(msg); } };
//==========End Class CreateRandomArrayException==========