?? emp.java
字號:
import java.util.*; //use class: Random & Vector
public class Emp
{
private static Vector allIDs = new Vector();
private static Random r = new Random();
private static final String SIGN = "#";
private String id;
public Emp(String n) // Constructor
{
setID(n);
}
public void setID(String name)
{
validateID(name);
}
public String getID()
{
return id;
}
public static void list()
{
Enumeration e = allIDs.elements();
while(e.hasMoreElements())
System.out.println(e.nextElement());
}
private void validateID(String name)
{
String s = new String("");
while(allIDs.contains(name+s))
s = SIGN + Math.abs(r.nextInt());
id = name + s;
allIDs.addElement(id);
}
public static void main(String args[])
{
Emp e1 = new Emp("John");
Emp e2 = new Emp("John");
Emp e3 = new Emp("John");
Emp e4 = new Emp("John");
System.out.println("e1:"+e1.getID());
System.out.println("e2:"+e2.getID());
System.out.println("e3:"+e3.getID());
System.out.println("e4:"+e4.getID());
Emp.list();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -