JavaDemo——表驱动

参考:https://blog.csdn.net/chgaowei/article/details/6966857

简单Demo:

/**
 * 2018年10月16日下午6:04:29
 */
package testDataDrive;

import java.util.ArrayList;
import java.util.List;

/**
 * @author XWF
 *
 */
public class TestDataDrive {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(Date.getTeachersName(CLASS.CLASSA, COURSE.English));
		System.out.println(Date.getTeachersName(CLASS.CLASSA, COURSE.Math));
		System.out.println(Date.getTeachersName(CLASS.CLASSB, COURSE.English));
		System.out.println(Date.getTeachersName(CLASS.CLASSB, COURSE.Math));
	}

}
enum CLASS{
	CLASSA,
	CLASSB;
}
enum COURSE{
	English,
	Math;
}
class ClassAndCourse{
	CLASS cls;
	COURSE course;
	String teacherName;
	public ClassAndCourse(CLASS cls, COURSE course, String teacherName) {
		this.cls = cls;
		this.course = course;
		this.teacherName = teacherName;
	}
	
}
class Date{
	static List list = new ArrayList<>();
	static {
		list.add(new ClassAndCourse(CLASS.CLASSA, COURSE.English, "小王"));
		list.add(new ClassAndCourse(CLASS.CLASSA, COURSE.Math, "小张"));
		list.add(new ClassAndCourse(CLASS.CLASSB, COURSE.English, "也是小王"));
		list.add(new ClassAndCourse(CLASS.CLASSB, COURSE.Math, "小李"));
	}
	
	public static String getTeachersName(CLASS cls,COURSE course) {
		String name = null;
		for(ClassAndCourse x:list) {
			if(x.cls.equals(cls) && x.course.equals(course)) {
				name = x.teacherName;
				break;
			}
		}
		return name;
	}
}

结果:

你可能感兴趣的:(JavaDemos,数据驱动编程,表驱动)