package homework1;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Vector;
public class BayesianNetwork {
public static final String Less="<45";
public static final String Middle="45-55";
public static final String More=">=55";
enum A{Less,Middle,More};
public class NodeA extends Node{
A value;
}
enum G{Female,Male};
public class NodeG extends Node{
G value;
}
enum CP{Typical,Atypical,NonAnginal,None};
public class NodeCP extends Node{
CP value;
}
enum BP{Low,High};
class NodeBP extends Node{
BP value;
}
enum CH{Low,High};
class NodeCH extends Node{
CH value;
}
enum ECG{Normal,Abnormal};
class NodeECG extends Node{
ECG value;
}
enum HR{Low,High};
class NodeHR extends Node{
HR value;
}
enum EIA{No,Yes};
class NodeEIA extends Node{
EIA value;
}
enum HD{No,Yes};
class NodeHD extends Node{
HD value;
}
class Node{
public Vector<Node> parent;
public String name;
public int cpt[];
public Node(){
this.parent=new Vector<Node>();
cpt=new int[64];
}
}
public static void main(String[] args) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, Exception, NoSuchMethodException
{
Vector <Node> nodeList=new Vector<Node>();
String[] nameList={"A","G","CP","BP","CH","ECG","HR","EIA","HD"};
System.out.println(NodeA.class);
for(String a:nameList)
{
Class newoneClass = Class.forName("homework1.BayesianNetwork$Node"+a);//classname也不一样
Constructor cons = newoneClass.getDeclaredConstructors()[0];
cons.setAccessible(true);
Object node= cons.newInstance(new BayesianNetwork()); //需要的是外部类的构造方法 }
}
nodeList.add((Node) node);
}
posted on 2012-02-16 09:17
luis 阅读(588)
评论(0) 编辑 收藏 引用 所属分类:
Java笔记