⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdata.java

📁 纯JAVA代码的考试系统
💻 JAVA
字号:
package org.fangsoft.testcenter.data;

import java.util.HashMap;

import org.fangsoft.testcenter.model.ChoiceItem;
import org.fangsoft.testcenter.model.Question;
import org.fangsoft.testcenter.model.Test;
import org.fangsoft.testcenter.model.test.JavaTest;
import org.fangsoft.testcenter.model.test.WebTest;

public class TestData {
	public static final String RIGHT_CHOICE="#";
	
	private static final String[][] JAVA_QUESTION_LIB={
		//test属性:name  , numQuestion  , timeLimitMin , description,score
			{  "java知识测试",
				"3",
			    "10",
			    "www.fangsoft.org的java知识测试",
			    "10"
			 },
		
			 //Question属性:diff,usedCount,enabled
			{
				//Question属性:name
				"有关java语言论述正确是?",
					//ChoiceItem
					"#它是一门编程语言",
					"#它是一个平台",
					"#它是跨平台的",
					"#它是面向对象的"
			},
			{
				"Java学习常可以参考的网站有?",
					"#java.sun.com",
					"#www.javaworld.com",
					"#www-130.ibm.com/developerworks/",
					"#www.fangsoft.org"
			},
			
			{
				"如果一个属性用private声明,下面论述正确的是?",
					"不可变",
					"同步(synchronized)",
					"#封装",
					"代表is-a关系"
			}
		};
	
	private static final String[][] WEB_QUESTION_LIB={
		//test属性:name  , numQuestion  , timeLimitMin , description,score
			{  "web知识测试",
				"3",
			    "10",
			    "www.fangsoft.org的web知识测试",
			    "10"
			 },
			{
				//Question属性:name
				"有关web论述正确是?",
					//ChoiceItem
					"#它应用了Http协议",
					"#常用的web服务器为Apache",
					"#web动态应用常用Jsp开发",
					"#Http协议有1.1版"
			},
			{
				"Web学习常可以参考的网站有?",
					"#java.sun.com",
					"#www.javaworld.com",
					"#www-130.ibm.com/developerworks/",
					"#www.fangsoft.org"
			},
			
			{
				"J2ee中的Web开发技术有",
					"#Jsp",
					"#servlet",
					"#JSF",
					"#Custom tags"
			}
		};
	
	
	public static HashMap<String,String> getAllTest(){
		HashMap<String,String> tests=new HashMap<String,String>();
		tests.put("java", "org.fangsoft.testcenter.model.test.JavaTest");
		tests.put("web", "org.fangsoft.testcenter.model.test.WebTest");
		return tests;
	}
	
      public static void loadQuestion(JavaTest test){
    	  loadQuestionFromArray(test,JAVA_QUESTION_LIB);
      }
      
    
      public static void loadQuestion(WebTest test){
    	  loadQuestionFromArray(test,WEB_QUESTION_LIB);
      }
      
      public static void initTest(JavaTest test){
    	  initTest(test,JAVA_QUESTION_LIB);
      }
      
      public static void initTest(WebTest test){
    	  initTest(test,WEB_QUESTION_LIB);
      }
      
      public static void initTest(Test test){
    	  if(test instanceof JavaTest){
    		  initTest((JavaTest)test);
    	  }else if(test instanceof WebTest){
    		  initTest((WebTest)test);
    	  }
      }
      
      public static void initTest(Test test,String[][] testData){
    	String[] tds=testData[0];
  		int numQuestion=Integer.parseInt(tds[1]);
  		int numQ=testData.length;
  		if(numQuestion>(numQ-1))numQuestion=numQ-1;
  		test.setName(tds[0]);
  		test.setNumQuestion(numQuestion);
  		test.setTimeLimitMin(Integer.parseInt(tds[2]));
  		test.setDescription(tds[3]);
  		test.setScore(Integer.parseInt(tds[4]));
      }
      
	public static void loadQuestionFromArray(Test test,String[][] testData) {
		int qi=0;
		while(qi<testData.length-1){
			String[] qds=testData[qi+1];
			Question q=new Question();
			q.setName(qds[0]);
			//choice
			//ChoiceItem[] items=new ChoiceItem[qds.length-1];
			for(int j=1;j<qds.length;j++){
				ChoiceItem ch=new ChoiceItem();
				String choiceText=qds[j];
				if (choiceText.indexOf(RIGHT_CHOICE)==0){
					choiceText=choiceText.substring(1);
					ch.setCorrect(true);
				}
				ch.setName(choiceText);
				//items[j-1]=ch;
				q.addChoiceItem(ch);
			}
			//q.setChoiceItem(items);
			q.setScore(1);
			test.addQuestion(q);
			qi++;
		}
		//return test;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -