import java.applet.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.math.BigInteger;import java.text.*;import java.util.HashMap;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Licenses extends Applet {	private static final byte ASCII_0 = 48;	private static HashMap DLFMR_FIRST_MALE = new HashMap();	private static HashMap DLFMR_FIRST_FEMALE = new HashMap();	private static HashMap DLFMR_FIRST_INIT = new HashMap();	private static HashMap DLFMR_MIDDLE_INIT = new HashMap();	private static HashMap DLFM_FIRST_MALE = new HashMap();	private static HashMap DLFM_FIRST_FEMALE = new HashMap();	private static HashMap DLFM_FIRST_INIT = new HashMap();	private static HashMap DLFM_MIDDLE_INIT = new HashMap();	private static HashMap datetbl = null;	private static HashMap database = null;	private static HashMap table = null;	private static String results, input;	private String func = null,state = null;	private Pattern p = null;		// Results 	private	String first_name = null, middle_init = null, last_name_sound = null, gender = null;	private String[] similar_last_names = null;	private	String month = null;	private int day = -1;	private String year = null;		private String error = null;				static {		init_FIRST_MALE();		reverse(DLFMR_FIRST_MALE,DLFM_FIRST_MALE);		init_FIRST_FEMALE();		reverse(DLFMR_FIRST_FEMALE,DLFM_FIRST_FEMALE);		init_FIRST_INIT();		reverse(DLFMR_FIRST_INIT,DLFM_FIRST_INIT);		init_MIDDLE_INIT();		reverse(DLFMR_MIDDLE_INIT,DLFM_MIDDLE_INIT);	}		public void init() {	} 	private static void reverse(HashMap from,HashMap to) {		Object[] keys = from.keySet().toArray();		for (int i=0;i<keys.length;i++) {			Object o = from.get(keys[i]);			if (o instanceof String) 				to.put(((String)o).toUpperCase(),keys[i]);			else {				String[] samekeys = (String[])o;				for (int j=0;j<samekeys.length;j++)					to.put(samekeys[j].toUpperCase(),keys[i]);			}		}	}			/**	 * initialize based on function chosen	 */	public void chose(String choice) {		func = choice;		if (func.equals("dl_wi") || func.equals("dl_wir")) {			state = "Wisconsin";			p = Pattern.compile("([A-Za-z]\\d\\d\\d)-(\\d\\d\\d)(\\d)-(\\d)(\\d\\d\\d)-(..)");		}		else if (func.equals("dl_md")) {			state = "Maryland";		}		else if (func.equals("dl_mi")) {			state = "Michigan";		}		else if (func.equals("dl_mn")) {			state = "Minnesota";		}		else if (func.equals("dl_nh")) {			state = "New Hampshire";		}		else if (func.equals("dl_ny")) {			state = "New York(pre 1992)";		}		else if (func.equals("dl_wa")) {			state = "Washington";		}		else if (func.equals("dl_il") || func.equals("dl_ilr")) {			state = "Illinois";			p = Pattern.compile("([A-Za-z]\\d\\d\\d)-(\\d\\d\\d)(\\d)-(\\d)(\\d\\d\\d)");		}		else if (func.equals("dl_fl") || func.equals("dl_flr")) {			state = "Florida";			p = Pattern.compile("([A-Za-z]\\d\\d\\d)-(\\d\\d\\d)-(\\d)(\\d)-(\\d\\d\\d)");		}		else state = "Unknown";	}			/**	 * Return current state being worked on. Set in <code>chose</code> 	 */	public String getState() { return state; }		/**	 * Calculate drivers license number from individuals information	 */	public void calc(String first,String middle,String last,String gender,int yy,int mm,int dd) {		last = last.trim();		middle = middle.trim();		first = first.trim();		if (need_dob_year()) {			if (yy < 2000) yy -= 1900;			else yy -= 2000;			if (yy > 99 || yy < 0)				throw new IllegalArgumentException("Invalid year of birth");		}				if (need_dob_month()) {			if (mm > 12 || mm < 1)				throw new IllegalArgumentException("Invalid month");		}				if (need_dob_day()) {			if (dd > 31 || dd < 1)				throw new IllegalArgumentException("Invalid day");		}				if (need_gender()) {			if (!gender.equals("M") && !gender.equals("F"))				throw new IllegalArgumentException("Invalid gender");		}				results = encode_drivers_license(last,first,middle,gender,yy,mm,dd);			}		private String encode_drivers_license(String last,String first,String middle,String gender,int yy,int mm,int dd) {/*	# http://www.academic.marist.edu/mwa/wsdln.htm	#	# LLLLLFMYYXmd	# LLLLL - First five letters of last name, padded with * if necessary	# F - First initial	# M - Middle initial, * if not avail	# YY - 100 - two digit year of birth (probably 00 for 1900 or 2000)	# X - Check digit	# m - Encoded birth month (Two options!)	# d - Encoded birth day*/		if (func.equals("dl_wa")) {			last = new StringBuffer(last).append("****").substring(0,5).toUpperCase();			if (middle == null || middle.equals("")) middle = "*";			middle = middle.substring(0,1).toUpperCase();			first = first.substring(0,1).toUpperCase();			int yearcal = 100 - yy;			if (yearcal == 100) yearcal = 0;			yy = yearcal;			String[] mms = encode_month(mm);			String d = encode_day(dd);			StringBuffer prefix = new StringBuffer(last).append(first).append(middle).append(yy);			String guess1 = new StringBuffer(prefix).append("?").append(mms[0]).append(d).toString();			String guess2 = new StringBuffer(prefix).append("?").append(mms[1]).append(d).toString();			guess1 = add_checksum(guess1);			guess2 = add_checksum(guess2);			return new StringBuffer(guess1).append(" or ").append(guess2).toString();		}/*	# http://www.cis.famu.edu/~riggs/CProg/Prog2Sp02.html	# 	# First Name: Alvy	# Middle Initial: J	# Last Name: Singer	# Gender: M	# Date of Birth: 	#    Year: 1935	#    Month: 1	#    Day: 13	# S09507457182808935		# Enter your last name: singer	# Enter your first name: alvy	# Enter your middle initial: j	# Your birth year: 1935	# Your birth month: 1	# Your birth day: 13	# Your sex (0 - male, 1-female): 0	# Your license number is : S09507457182808935	# 	# Julia Ho Oct 2, 1950	# H14989504785463550	#             ^- Unsure, probably right.*/		else if (func.equals("dl_ny")) {			byte[] b = new byte[5];			byte[] blast = last.toUpperCase().getBytes();			System.arraycopy(blast,0,b,0,blast.length);			String l1 = last.substring(0,1);			byte l2 = letter_to_num(b[1]);			byte l3 = letter_to_num(b[2]);			byte l4 = letter_to_num(b[3]);			byte l5 = letter_to_num(b[4]);			byte[] bmiddle = middle.substring(0,1).toUpperCase().getBytes();			byte m1 = letter_to_num(bmiddle[0]);			b = new byte[3];			byte[] bfirst = first.toUpperCase().getBytes();			System.arraycopy(bfirst,0,b,0,Math.min(bfirst.length,b.length));			byte f1 = letter_to_num(b[0]);			byte f2 = letter_to_num(b[1]);			byte f3 = letter_to_num(b[2]);						int x = 385829132;			if (last.length() == 3)				x = 385318778;			else if (last.length() < 3)				x = 371539194;			BigInteger bignum = new BigInteger("10017758323").multiply(new BigInteger(new Integer(l2).toString()));			BigInteger bigsum = new BigInteger((new Long((long)371538441 * l3							+ 13779585 * l4							+ 510355 * l5							+ 19657 * f1							+ 729 * f2							+ 27 * f3							+ m1							- x).toString()));			bignum = bignum.add(bigsum);			char[] padding = new char[] { '0','0','0','0','0','0','0','0','0','0','0','0' };			StringBuffer numout = new StringBuffer(bignum.toString());			if (numout.length() < 12)				numout.insert(0,padding,0,12-numout.length());			int dobnum = 63 * mm + 2 * dd;			if (gender.equals("F")) dobnum++;			NumberFormat fdob = new DecimalFormat("000");			String dob = fdob.format(dobnum);			String yystr = new Integer(yy).toString();			if (yystr.length() == 4) yystr = yystr.substring(2,2);			return new StringBuffer(l1).append(numout.toString()).append(dob).append("?").append(yystr).toString();		}		else if (func.equals("dl_nh")) {			String lastfirst = last.substring(0,1).toUpperCase();			String lastlast = last.substring(last.length()-1,last.length()).toUpperCase();			first = first.substring(0,1).toUpperCase();			NumberFormat pad2 = new DecimalFormat("00");			return new StringBuffer(pad2.format(mm)).append(lastfirst).append(lastlast).append(first).append(pad2.format(yy)).append(pad2.format(dd)).append("?").toString();					}		else if (func.equals("dl_md") || func.equals("dl_mi") || func.equals("dl_mn")) {			String q1 = Soundex.soundex(last);			String[] encoded = encode_first_middle(first,middle);			String q2 = encoded[0];			String q3 = encoded[1];			String q4 = encode_month_day(mm,dd);			return new StringBuffer(q1).append("-").append(q2).append("-").append(q3).append("-").append(q4).toString();		}		else {			middle = middle.substring(0,1);			int yytemp = yy % 100;			int yearTens = yytemp / 10;			int yearOnes = yy % 10;			String dl = format_license(Soundex.soundex(last),				dlfirstmiddle_encode(first,middle),				new Integer(yearTens).toString(),new Integer(yearOnes).toString(),				month_day_gender(mm,dd,gender));			return dl;		}	}		private String dlfirstmiddle_encode(String first,String middle) {		first = first.toUpperCase();		String first_init = first.substring(0,1);		middle = middle.toUpperCase();		int nameNum;		if (DLFM_FIRST_MALE.get(first) != null) 			nameNum = ((Integer)DLFM_FIRST_MALE.get(first)).intValue();		else if (DLFM_FIRST_FEMALE.get(first) != null)			nameNum = ((Integer)DLFM_FIRST_FEMALE.get(first)).intValue();		else if (DLFM_FIRST_INIT.get(first_init) != null)			nameNum = ((Integer)DLFM_FIRST_INIT.get(first_init)).intValue();		else return "BAD";				if (DLFM_MIDDLE_INIT.get(middle) != null)			nameNum += ((Integer)DLFM_MIDDLE_INIT.get(middle)).intValue();		else return "BAD";				String retvalue = new Integer(nameNum).toString();		if (retvalue.length() != 3)			retvalue = retvalue.substring(0,3);		return retvalue;	}		private String month_day_gender(int mm,int dd,String gender) {		gender = gender.toUpperCase();				int dateNo = (mm - 1) * month_mult() + dd;		if (gender.equals("F")) dateNo += female_add();		String retvalue = new Integer(dateNo).toString();		if (retvalue.length() != 3)			retvalue = retvalue.substring(0,3);		return retvalue;					}		private String format_license(String last_soundex,String first_middle_code,		String year_tens,String year_ones,String month_day_gender_code) {				if (func.equals("dl_wi")) {			StringBuffer dlbuff = new StringBuffer(last_soundex).append("-");			dlbuff.append(first_middle_code);			dlbuff.append(year_tens).append("-");			dlbuff.append(year_ones).append(month_day_gender_code);			dlbuff.append("-??");			return dlbuff.toString();		}		else if (func.equals("dl_il")) {			StringBuffer dlbuff = new StringBuffer(last_soundex).append("-");			dlbuff.append(first_middle_code).append(year_tens).append("-");			dlbuff.append(year_ones).append(month_day_gender_code);			return dlbuff.toString();		}		else if (func.equals("dl_fl")) {			StringBuffer dlbuff = new StringBuffer(last_soundex).append("-");			dlbuff.append(first_middle_code).append("-");			dlbuff.append(year_tens).append(year_ones).append("-");			dlbuff.append(month_day_gender_code);			return dlbuff.toString();		}		return null;	}		// The following routines are specific to the md,mi and mn calculations	private String[] encode_first_middle(String first,String middle) {		first = first.toUpperCase();		middle = middle.toUpperCase();		String[] firstenc = encode_name(first);		String first_encoded = firstenc[0];		String first_next = firstenc[1];		String middle_encoded = "???";		if (middle != null & middle.length() > 0) 			middle_encoded = encode_name(middle)[0];		else if (first_next == null || first_next.length() == 0 || first_next.equals("???"))			middle_encoded = "000";		else if (first_next != null && first_next.length() > 0) {			byte[] b = first_next.toUpperCase().getBytes();			b[0] -= 64;			NumberFormat pad3 = new DecimalFormat("000");			middle_encoded = pad3.format(b[0]);		}		return new String[] { first_encoded,middle_encoded };	}		private String encode_month_day(int mm,int dd) {		if (datetbl == null) {			try {				InputStream is = Licenses.class.getResourceAsStream("datetbl.ser");				ObjectInputStream ois = new ObjectInputStream(is);				datetbl = (HashMap)ois.readObject();			}			catch (Throwable tossed) {				throw new IllegalStateException("Licenses: unable to obtain serialized date table");			}		}		NumberFormat pad2 = new DecimalFormat("00");		String key = new StringBuffer(pad2.format(mm)).append("-").append(pad2.format(dd)).toString();		String value = (String)datetbl.get(key);		if (value == null) 			throw new IllegalArgumentException("Licenses: month day table messed up for " + mm + ", " + dd);		return value;	}		private String[] encode_name(String name) {		name = name.toLowerCase();		String next = null;		if (table == null) {			try {				InputStream is = Licenses.class.getResourceAsStream("enctbl.ser");				ObjectInputStream ois = new ObjectInputStream(is);				table = (HashMap)ois.readObject();			}			catch (Throwable tossed) {				throw new IllegalStateException("Licenses: unable to obtain serialized date table");			}		}		String encoding = (String)table.get(name);		if (encoding != null) 			return new String[] { encoding,"" };		if (name.length() > 3) {			next = name.substring(3,4);			name = name.substring(0,3);			encoding = (String)table.get(name);			if (encoding != null) 				return new String[] { encoding,next };		}		if (name.length() > 2) {			next = name.substring(2,3);			name = name.substring(0,2);			encoding = (String)table.get(name);			if (encoding != null)				return new String[] { encoding,next };		}		return new String[] { "???",null };	}		// The following routine is specific to state of New York pre-1992 calculations	private byte letter_to_num(byte c) {		if (c < 65 || c > 90) return 0;		// A = 65, Z = 90		return (byte)(c - 65 + (byte)1);	}		// The following routines are specific to state of Washington calculations	private byte letter_to_digit(byte c) {/*		#'*'=>0, # marist.edu site claims this		'*'=>4,  # This appears correct (from email)*/		if (c == '*') return (byte)4;		if (c == '?') return (byte)0;		int ascii = (int)c;		if (ascii > 47 && ascii < 58) return (byte)(ascii - 48);		if (ascii < 74) return (byte)(ascii - 64);		else if (ascii < 83) return (byte)(ascii - 73);		else return (byte)(ascii - 81);	}		private String add_checksum(String val) {		byte[] a = new StringBuffer("?").append(val).toString().getBytes();		char[] orig = val.toCharArray();		for (int i=0;i<a.length;i++) 			a[i] = letter_to_digit(a[i]);		int csum = perlmod(a[1] - a[2] + a[3] - a[4] + a[5] - a[6] + a[7] - a[8] + a[9] - a[11] + a[12],10);		orig[9] = (char)(csum + ASCII_0);		return new String(orig);	}		// For (bug for bug?) compatability with the perl cgi	private int perlmod(int num, int divisor) {		int interim = num % divisor;		if (num >= 0) return interim;		return divisor + interim;	}		private String encode_day(int day) {		String[] day_code = new String[] { "_","A","B","C","D","E","F","G","H","Z","S","J","K","L","M","N","W","P","Q","R","0","1","2","3","4","5","6","7","8","9","T","U" };		return day_code[day];	}		private String[] encode_month(int mm) {		if (mm < 1 || mm > 12) return null;		//                                          Jan 1      Feb 2      Mar 3      Apr 4      May 5      Jun 6      Jul 7      Aug 8      Sep 9      Oct 10     Nov 11     Dec 12  		String[][] month_codes = new String[][] { {"B","S"}, {"C","T"}, {"D","U"}, {"J","1"}, {"K","2"}, {"L","3"}, {"M","4"}, {"N","5"}, {"O","6"}, {"P","7"}, {"Q","8"}, {"R","9"} };		return month_codes[mm-1];	}		public String getResult() { return results; }		/**	 * Reverse calculate individuals information from the drivers license number	 */	public void calcr(String s) {		error = "";		gender = "M";		Matcher m = p.matcher(s);		if (!m.matches()) {				error = "ERROR: License number had an invalid format";			return;		}		String last = null, year_ten = null, year_one = null;		int first_middle = 0, day_month = 0;				if (func.equals("dl_wir")) {			String[] parts = s.split("-");			if (parts.length != 4) {				error = "ERROR: License number was not in four parts";				return;			}			last = parts[0].toUpperCase();					first_middle = new Integer(parts[1].substring(0,3)).intValue();			year_ten = parts[1].substring(3);			year_one = parts[2].substring(0,1);			day_month = new Integer(parts[2].substring(1)).intValue();			if (day_month > 500) {				gender = "F";				day_month -= 500;			}			String count = parts[3];		}		else if (func.equals("dl_ilr")) {			String[] parts = s.split("-");			if (parts.length != 3) {				error = "ERROR: License number was not in three parts";				return;			}			last = parts[0].toUpperCase();					first_middle = new Integer(parts[1].substring(0,3)).intValue();			year_ten = parts[1].substring(3);			year_one = parts[2].substring(0,1);			day_month = new Integer(parts[2].substring(1)).intValue();			if (day_month > 600) {				gender = "F";				day_month -= 600;			}		}		else if (func.equals("dl_flr")) {			String[] parts = s.split("-");			if (parts.length != 4) {				error = "ERROR: License number was not in four parts";				return;			}			last = parts[0].toUpperCase();					first_middle = new Integer(parts[1]).intValue();			year_ten = parts[2].substring(0,1);			year_one = parts[2].substring(1);			day_month = new Integer(parts[3]).intValue();			if (day_month > 500) {				gender = "F";				day_month -= 500;			}		}		first_name = dlfirstmiddle_first_from_code(first_middle,gender);		middle_init = dlfirstmiddle_middle_from_code(first_middle);		last_name_sound = describe_soundex(last);//		String last_name_sound_guess = soundex_sound_guess(last);		similar_last_names = soundex_similar_last_names(last);		month = month_name(day_month);		day = day(day_month);		year = year_ten + year_one;	}	public String getFirstName() { return first_name; }	public String getMiddleInit() { return middle_init; }	public String getLastNameSound() { return last_name_sound; }	public String getLastNameGuesses() { return concat(similar_last_names); }	public String getGender() { 		if (gender.toUpperCase().equals("M")) return "male";		else return "female";	}	public String getBirthDate() {		String year_thousands_guess = "19";		return new StringBuffer(month).append(" ").append(day).append(", ").append(year_thousands_guess).append(year).toString();	}	public String getGuess() {		// Some time around 2016 this will start to be more wrong than it is 		// right for '00'.		String year_thousands_guess = "19";		StringBuffer tempout = new StringBuffer(first_name).append(" ").append(middle_init).append(".");		tempout.append(" ").append(similar_last_names[0]).append(" ");		tempout.append(" born ").append(month).append(" ").append(day).append(", ");		tempout.append(year_thousands_guess).append(year);		return tempout.toString();	}		private String concat(String[] a) {		if (a.length == 0) return "";		StringBuffer resbuff = new StringBuffer(a[0]);		for (int i=1;i<a.length;i++) 			resbuff.append(" ").append(a[i]);		return resbuff.toString();	}		private String dlfirstmiddle_first_from_code(int code,String gender) {		code -= (code % 20);		String probable = null,improbable = null;		Integer codekey = new Integer(code);		Object o = DLFMR_FIRST_FEMALE.get(codekey);		String female = null;		if (o != null) {			if (o instanceof String) female = (String)o;			else female = ((String[])o)[0];		}		String male = (String)DLFMR_FIRST_MALE.get(codekey);			if (male != null && gender.equals("M")) {			probable = male;			improbable = female;		}		else if (female != null && gender.equals("F")) {			probable = female;			improbable = male;		}		if (probable == null) {			String init = (String)DLFMR_FIRST_INIT.get(codekey);			if (init != null) 				probable = init + ".";		}		if (probable == null) return "X";		StringBuffer retvalue = new StringBuffer(probable);		if (improbable != null)			retvalue.append(" (or possibly ").append(improbable).append(")");		return retvalue.toString();	}		private String dlfirstmiddle_middle_from_code(int code) {		code %= 20;		Integer codekey = new Integer(code);		String answer = (String)DLFMR_MIDDLE_INIT.get(codekey);		if (answer == null) return "";		return answer;	}		private String describe_soundex(String name) {		char[] parts = name.toCharArray();		StringBuffer retvalue = new StringBuffer("Starts with a ").append(parts[0]);		for (int i=1;i<parts.length;i++) {			retvalue.append(", followed by a ");			if (parts[i] == '1') retvalue.append("labial (B, F, P, or V)");			else if (parts[i] == '2') retvalue.append("gutteral or sibilant (C, G, J, K, Q, S, X, or Z)");			else if (parts[i] == '3') retvalue.append("dental (D or T)");			else if (parts[i] == '4') retvalue.append("long liquid (L)");			else if (parts[i] == '5') retvalue.append("nasal (M or N)");			else if (parts[i] == '6') retvalue.append("short liquid (R)");			break;		// mjh - looping through parts doesn't seem to work right and the original uniqueid didn't seem to?		}		retvalue.append(".");		return retvalue.toString();	}		private String soundex_sound_guess(String name) {		char[] parts = name.toCharArray();		StringBuffer retvalue = new StringBuffer(parts[0]).append("e");		for (int i=1;i<parts.length;i++) {			if (parts[i] == '1') retvalue.append("be");			// bfpv			else if (parts[i] == '2') retvalue.append("se");	// cgjkqsxz			else if (parts[i] == '3') retvalue.append("te");	// td			else if (parts[i] == '4') retvalue.append("le");	// l			else if (parts[i] == '5') retvalue.append("me");	// mn			else if (parts[i] == '6') retvalue.append("re");	// r		}		return retvalue.toString();	}		private String[] soundex_similar_last_names(String soundex) {		HashMap database = soundex_database();		if (database == null) {			return new String[] { "<Name database unavailable. Unable to display name guesses>" };		}		String names_line = (String)database.get(soundex);		if (names_line == null) {			return new String[] { "<No entry in name database for soundex value>" };		}		String[] names = names_line.split(", ");		for (int i=0;i<names.length;i++) {			StringBuffer name = new StringBuffer(names[i]);			name.setCharAt(0,Character.toUpperCase(name.charAt(0)));			names[i] = name.toString();		}		return names;	}	private HashMap soundex_database() {		if (database != null) return database;		try {			InputStream is = Licenses.class.getResourceAsStream("soundex.txt");			BufferedReader rdr = new BufferedReader(new InputStreamReader(is));			HashMap database = new HashMap();			String s = rdr.readLine();			while (s != null) {				String[] dbparts = s.split("\t");				if (dbparts.length > 1)					database.put(dbparts[0],dbparts[1]);				s = rdr.readLine();			}			rdr.close();			return database;		}		catch (Exception ex) { ex.printStackTrace(); }		return null;	}	private int month_mult() {		if (func.equals("dl_wir") || func.equals("dl_wi")) return 40;		else if (func.equals("dl_ilr") || func.equals("dl_il")) return 31;		else if (func.equals("dl_flr") || func.equals("dl_fl")) return 40;		return 0;	}	private int female_add() {			if (func.equals("dl_wir") || func.equals("dl_wi")) return 500;		else if (func.equals("dl_ilr") || func.equals("dl_il")) return 600;		else if (func.equals("dl_flr") || func.equals("dl_fl")) return 500;		return 0;	}			private int day(int input) {		input %= female_add();		return (input % month_mult());	}		private int month_num(int input) {		int adjust_input = input % female_add();		return (input - day(adjust_input)) / month_mult() + 1;	}		private String month_name(int input) {		String[] months = new String[] { "January","February","March","April","May","June",			"July","August","September","October","November","December" };		int num = month_num(input);		if (num < 1 || num > 12) return "BADMONTH";		return months[num-1];	}		private String getInput() {		StringBuffer inbuff = new StringBuffer(input);		int idx = inbuff.indexOf("STATE");		while (idx > -1) {			inbuff.replace(idx,idx+5,state);			idx = inbuff.indexOf("STATE");		}		idx = inbuff.indexOf("FUNC");		inbuff.replace(idx,idx+func.length(),func);		return inbuff.toString();	}		private String getResults() {		StringBuffer resbuff = new StringBuffer(results);		int idx = resbuff.indexOf("STATE");		while (idx > -1)  {			resbuff.replace(idx,idx+5,state);			idx = resbuff.indexOf("STATE");		}		return resbuff.toString();	}		public String getError() {		if (error == null)			return "No error";		else if (error.equals(""))			return "No error";		return error;	}		private boolean need_last_name() { return true; }	private boolean need_first_name() { return true; }	private boolean need_middle_initial() { 		if (func.equals("dl_nh") || func.equals("dl_md") || func.equals("dl_mi") || func.equals("dl_mn")) 			return false;		return true; 	}	private boolean need_middle_name() {		if (func.equals("dl_md") || func.equals("dl_mi") || func.equals("dl_mn"))			return true;		return false;	}		public boolean need_gender() { 		if (func.equals("dl_wa") || func.equals("dl_nh") || func.equals("dl_md") || func.equals("dl_mi") || func.equals("dl_mn"))			return false;		return true; 	}	private boolean need_dob_year() { 		if (func.equals("dl_md") || func.equals("dl_mi") || func.equals("dl_mn"))			return false;		return true; 	}	private boolean need_dob_month() { return true; }	private boolean need_dob_day() { return true; }		private static void init_FIRST_MALE() {		DLFMR_FIRST_MALE.put(new Integer(20),"Albert");		DLFMR_FIRST_MALE.put(new Integer(40),"Arthur");		DLFMR_FIRST_MALE.put(new Integer(80),"Bernard");		DLFMR_FIRST_MALE.put(new Integer(120),"Carl");		DLFMR_FIRST_MALE.put(new Integer(140),"Charles");		DLFMR_FIRST_MALE.put(new Integer(180),"Donald");		DLFMR_FIRST_MALE.put(new Integer(220),"Edward");		DLFMR_FIRST_MALE.put(new Integer(260),"Frank");		DLFMR_FIRST_MALE.put(new Integer(300),"George");		DLFMR_FIRST_MALE.put(new Integer(340),"Harold");		DLFMR_FIRST_MALE.put(new Integer(360),"Harry");		DLFMR_FIRST_MALE.put(new Integer(380),"Henry");		DLFMR_FIRST_MALE.put(new Integer(440),"James");		DLFMR_FIRST_MALE.put(new Integer(460),"John");		DLFMR_FIRST_MALE.put(new Integer(480),"Joseph");		DLFMR_FIRST_MALE.put(new Integer(560),"Martin");		DLFMR_FIRST_MALE.put(new Integer(580),"Marvin");		DLFMR_FIRST_MALE.put(new Integer(600),"Melvin");		DLFMR_FIRST_MALE.put(new Integer(680),"Paul");		DLFMR_FIRST_MALE.put(new Integer(740),"Richard");		DLFMR_FIRST_MALE.put(new Integer(760),"Robert");		DLFMR_FIRST_MALE.put(new Integer(820),"Thomas");		DLFMR_FIRST_MALE.put(new Integer(900),"Walter");		DLFMR_FIRST_MALE.put(new Integer(920),"William");	}		private static void init_FIRST_FEMALE() {		DLFMR_FIRST_FEMALE.put(new Integer(20),"Alice");		DLFMR_FIRST_FEMALE.put(new Integer(40),new String[] { "Ann","Anna","Anne","Annie" });		DLFMR_FIRST_FEMALE.put(new Integer(80),new String[] { "Bette","Bettie","Betty" });		DLFMR_FIRST_FEMALE.put(new Integer(120),"Catherine");		DLFMR_FIRST_FEMALE.put(new Integer(140),"Clara");		DLFMR_FIRST_FEMALE.put(new Integer(180),"Dorothy");		DLFMR_FIRST_FEMALE.put(new Integer(220),"Elizabeth");		DLFMR_FIRST_FEMALE.put(new Integer(260),"Florence");		DLFMR_FIRST_FEMALE.put(new Integer(300),"Grace");		DLFMR_FIRST_FEMALE.put(new Integer(340),"Harriet");		DLFMR_FIRST_FEMALE.put(new Integer(360),"Hazel");		DLFMR_FIRST_FEMALE.put(new Integer(380),"Helen");		DLFMR_FIRST_FEMALE.put(new Integer(440),new String[] { "Jane","Jayne" });		DLFMR_FIRST_FEMALE.put(new Integer(460),"Jean");		DLFMR_FIRST_FEMALE.put(new Integer(480),"Joan");		DLFMR_FIRST_FEMALE.put(new Integer(580),"Mary");		DLFMR_FIRST_FEMALE.put(new Integer(600),"Mildred");		DLFMR_FIRST_FEMALE.put(new Integer(680),"Patricia");		DLFMR_FIRST_FEMALE.put(new Integer(740),"Ruby");		DLFMR_FIRST_FEMALE.put(new Integer(760),"Ruth");		DLFMR_FIRST_FEMALE.put(new Integer(820),"Thelma");		DLFMR_FIRST_FEMALE.put(new Integer(900),"Wanda");		DLFMR_FIRST_FEMALE.put(new Integer(920),"Wilma");	}		private static void init_FIRST_INIT() {		DLFMR_FIRST_INIT.put(new Integer(0),"A");		DLFMR_FIRST_INIT.put(new Integer(60),"B");		DLFMR_FIRST_INIT.put(new Integer(100),"C");		DLFMR_FIRST_INIT.put(new Integer(160),"D");		DLFMR_FIRST_INIT.put(new Integer(200),"E");		DLFMR_FIRST_INIT.put(new Integer(240),"F");		DLFMR_FIRST_INIT.put(new Integer(280),"G");		DLFMR_FIRST_INIT.put(new Integer(320),"H");		DLFMR_FIRST_INIT.put(new Integer(400),"I");		DLFMR_FIRST_INIT.put(new Integer(420),"J");		DLFMR_FIRST_INIT.put(new Integer(500),"K");		DLFMR_FIRST_INIT.put(new Integer(520),"L");		DLFMR_FIRST_INIT.put(new Integer(540),"M");		DLFMR_FIRST_INIT.put(new Integer(620),"N");		DLFMR_FIRST_INIT.put(new Integer(640),"O");		DLFMR_FIRST_INIT.put(new Integer(660),"P");		DLFMR_FIRST_INIT.put(new Integer(700),"Q");		DLFMR_FIRST_INIT.put(new Integer(720),"R");		DLFMR_FIRST_INIT.put(new Integer(780),"S");		DLFMR_FIRST_INIT.put(new Integer(800),"T");		DLFMR_FIRST_INIT.put(new Integer(840),"U");		DLFMR_FIRST_INIT.put(new Integer(860),"V");		DLFMR_FIRST_INIT.put(new Integer(880),"W");		DLFMR_FIRST_INIT.put(new Integer(940),"X");		DLFMR_FIRST_INIT.put(new Integer(960),"Y");		DLFMR_FIRST_INIT.put(new Integer(980),"Z");	}		private static void init_MIDDLE_INIT() {		DLFMR_MIDDLE_INIT.put(new Integer(0),new String[] { " ", "" });		DLFMR_MIDDLE_INIT.put(new Integer(1),"A");		DLFMR_MIDDLE_INIT.put(new Integer(2),"B");		DLFMR_MIDDLE_INIT.put(new Integer(3),"C");		DLFMR_MIDDLE_INIT.put(new Integer(4),"D");		DLFMR_MIDDLE_INIT.put(new Integer(5),"E");		DLFMR_MIDDLE_INIT.put(new Integer(6),"F");		DLFMR_MIDDLE_INIT.put(new Integer(7),"G");		DLFMR_MIDDLE_INIT.put(new Integer(8),"H");		DLFMR_MIDDLE_INIT.put(new Integer(9),"I");		DLFMR_MIDDLE_INIT.put(new Integer(10),"J");		DLFMR_MIDDLE_INIT.put(new Integer(11),"K");		DLFMR_MIDDLE_INIT.put(new Integer(12),"L");		DLFMR_MIDDLE_INIT.put(new Integer(13),"M");		DLFMR_MIDDLE_INIT.put(new Integer(14),new String[] { "N","O" });		DLFMR_MIDDLE_INIT.put(new Integer(15),new String[] { "P","Q" });		DLFMR_MIDDLE_INIT.put(new Integer(16),"R");		DLFMR_MIDDLE_INIT.put(new Integer(17),"S");		DLFMR_MIDDLE_INIT.put(new Integer(18),new String[] { "T","U","V" });		DLFMR_MIDDLE_INIT.put(new Integer(19),new String[] { "W","X","Y","Z" });	}}