生成试题基本算法和代码片段

来源:互联网 发布:哪里能找到辐射站数据 编辑:程序博客网 时间:2024/05/16 10:57

算法的基本思路:1、先根据各种条件从数据库中检索出数据分别把数据放如不同的集合中。2、在从每个集合中检索出N(先根据集合的大小,在集合范围内由一个随机算法生成需要的随机数)个符合条件的数据。放入到另外一个集合List.依此把所有检索的结果都放入到List中,最后返回List.

 

 

/**
* 根据详细的选择生成试题
*
*/
public ActionForward autoParticular(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {

 

   /**
   * 本方法返回值
   */
   List list = new ArrayList();

   /**
   * 获取主观题目的数量
   */
   // 获取主观题'易'的数量
   String subjectiveYi = request.getParameter('subjectiveYi');
   // 获取主观题'偏易'的数量
   String subjectivePianYi = request.getParameter('subjectivePianYi');
   // 获取主观题'中'的数量
   String subjectiveZhong = request.getParameter('subjectiveZhong');
   // 获取主观题'偏难'的数量
   String subjectivePianNan = request.getParameter('subjectivePianNan');
   // 获取主观题'难'的数量
   String subjectiveNan = request.getParameter('subjectiveNan');

   /**
   * 获取客观题目的数量
   */
   // 获取客观题'易'的数量
   String extensionYi = request.getParameter('extensionYi');
   // 获取客观题'偏易'的数量
   String extensionPianYi = request.getParameter('extensionPianYi');
   // 获取客观题'中'的数量
   String extensionZhong = request.getParameter('extensionZhong');
   // 获取客观题'偏难'的数量
   String extensionPianNan = request.getParameter('extensionPianNan');
   // 获取客观题'难'的数量
   String extensionNan = request.getParameter('extensionNan');

   /**
   * 获取范围
   */
   String testFanwei = null;
   testFanwei = (String) request.getParameter('testFanwei');
   request.setAttribute('testFw', testFanwei);

   // 获取题型的综合类型
   String zongHe = null;
   zongHe = request.getParameter('zongHe');

   // ===============================================================获取客观结果集合================================================================
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) '1':是指客观题目 '2':是指'易'的题目
   */
   List listEYi = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '1', '2', zongHe);
   System.out
     .println('listEYI ==============                 =============='
       + listEYi.size());
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) '1':是指'客观'题目 '4':是指'偏易'的题目
   */
   List listEPianYi = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '1', '4', zongHe);
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) '1':是指'客观'题目 '0':是指'中'的题目
   */
   List listEZhong = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '1', '0', zongHe);
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) '1':是指'客观'题目 '3':是指'偏难'的题目
   */
   List listEPianNan = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '1', '3', zongHe);

   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) 前者'1':是指'客观'题目 后者'1':是指'难'的题目
   */
   List listENan = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '1', '1', zongHe);
   // ===============================================================获取主观结果集合================================================================
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) 前'0':是指'主观'题目 后'2':是指'偏易'的题目
   */
   List listSYi = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '0', '2', zongHe);
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) '0':是指'主观'题目 '4':是指'偏易'的题目
   */
   List listSPianYi = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '0', '4', zongHe);
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) 前'0':是指'主观'题目 '0':是指'中'的题目
   */
   List listSZhong = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '0', '0', zongHe);
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) '0':是指'主观'题目 '3':是指'难'的题目
   */
   List listSPianNan = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '0', '3', zongHe);
   /**
   * 从数据库获取数据 testFanwei:是指考试类型(JAVA和.NET等) '0':是指'主观'题目 '1':是指'难'的题目
   */
   List listSNan = globalTestService.getSelectTestAutoModeListZongHe(
     testFanwei, '0', '1', zongHe);
   // ===============================================================产生相应要的随机数并并放入数组================================================================

   // 客观'易'的
   int eYi = Integer.parseInt(extensionYi);
   System.out.println('listSelect.size()=================' + eYi);
   RamGenerator rameYi = new RamGenerator(0, eYi - 1);
   rameYi.generate();
   int[] ceYi = new int[eYi];// 获取记录总数
   ceYi = rameYi.outPut();
   rameYi.output();

   // 客观'偏易'的
   int ePianYi = Integer.parseInt(extensionPianYi);
   System.out.println('listSelect.size()=================' + ePianYi);
   RamGenerator ramePianYi = new RamGenerator(0, ePianYi - 1);
   ramePianYi.generate();
   int[] cePianYi = new int[ePianYi];// 获取记录总数
   cePianYi = ramePianYi.outPut();
   ramePianYi.output();

   // 客观'中'的

   int eZhong = Integer.parseInt(extensionZhong);
   System.out.println('listSelect.size()=================' + eZhong);
   RamGenerator rameZhong = new RamGenerator(0, eZhong - 1);
   rameZhong.generate();
   int[] ceZhong = new int[eZhong];// 获取记录总数
   ceZhong = rameZhong.outPut();
   rameZhong.output();

   // 客观'偏难'的
   int ePianNan = Integer.parseInt(extensionPianNan);
   System.out.println('listSelect.size()=================' + ePianNan);
   RamGenerator ramePianNan = new RamGenerator(0, ePianNan - 1);
   ramePianNan.generate();
   int[] cePianNan = new int[ePianNan];// 获取记录总数
   cePianNan = ramePianNan.outPut();
   ramePianNan.output();

   // 客观'难'的
   int eNan = Integer.parseInt(extensionNan);
   System.out.println('listSelect.size()=================' + eNan);
   RamGenerator rameNan = new RamGenerator(0, eNan - 1);
   rameNan.generate();
   int[] ceNan = new int[eNan];// 获取记录总数
   ceNan = rameNan.outPut();
   rameNan.output();

   // 主观'易'的
   int sYi = Integer.parseInt(subjectiveYi);
   System.out.println('listSelect.size()=================' + sYi);
   RamGenerator ramesYi = new RamGenerator(0, sYi - 1);
   ramesYi.generate();
   int[] csYi = new int[sYi];// 获取记录总数
   csYi = ramesYi.outPut();
   ramesYi.output();

   // 主观'偏易'的
   int sPianYi = Integer.parseInt(subjectivePianYi);
   System.out.println('listSelect.size()=================' + sPianYi);
   RamGenerator ramesPianYi = new RamGenerator(0, sPianYi - 1);
   ramesPianYi.generate();
   int[] csPianYi = new int[sPianYi];// 获取记录总数
   csPianYi = ramesPianYi.outPut();
   ramesPianYi.output();

   // 主观'中'的
   int sZhong = Integer.parseInt(subjectiveZhong);
   System.out.println('listSelect.size()=================' + sZhong);
   RamGenerator ramesZhong = new RamGenerator(0, sZhong - 1);
   ramesZhong.generate();
   int[] csZhong = new int[sZhong];// 获取记录总数
   csZhong = ramesZhong.outPut();
   ramesZhong.output();

   // 主观'偏难'的
   int sPianNan = Integer.parseInt(subjectivePianNan);
   System.out.println('listSelect.size()=================' + sPianNan);
   RamGenerator ramesPianNan = new RamGenerator(0, sPianNan - 1);
   ramesPianNan.generate();
   int[] csPianNan = new int[sPianNan];// 获取记录总数
   csPianNan = ramesPianNan.outPut();
   ramesPianNan.output();

   // 主观'难'的
   int sNan = Integer.parseInt(subjectiveNan);
   System.out.println('listSelect.size()=================' + sNan);
   RamGenerator ramesNan = new RamGenerator(0, sNan - 1);
   ramesNan.generate();
   int[] csNan = new int[sNan];// 获取记录总数
   csNan = ramesNan.outPut();
   ramesNan.output();

   // ==========================================================把查询的所有结果放如list中======================================================================
   int i = 0, temp;
   /**
   * 添加客观'易'的到list 中
   */
   for (; i < eYi; i++) {
    temp = ceYi[i];
    // list.add(i,(GlobalTestModel) listSelectX.get(temp));
    try {
     list.add((GlobalTestModel) listEYi.get(temp));
    } catch (Exception e) {
     System.out.print(e);
    }
    System.out
      .println('list.add(i,(GlobalTestModel) listSelectX.get(temp));==================');
   }

   /**
   * 添加客观'偏易'的到list 中
   */
   for (int j = 0; j < ePianYi; j++) {
    temp = cePianYi[j];
    try {
     list.add((GlobalTestModel) listEPianYi.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   /**
   * 添加客观'中'的到list 中
   */
   for (int j = 0; j < eZhong; j++) {
    temp = ceZhong[j];
    try {
     list.add((GlobalTestModel) listEZhong.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   /**
   * 添加客观'偏难'的到list 中
   */
   for (int j = 0; j < ePianNan; j++) {
    temp = cePianNan[j];
    try {
     list.add((GlobalTestModel) listEPianNan.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   /**
   * 添加客观'难'的到list 中
   */
   for (int j = 0; j < eNan; j++) {
    temp = ceNan[j];
    try {
     list.add((GlobalTestModel) listENan.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   /**
   * 添加主观'易'的到list 中
   */

   for (int j = 0; j < sYi; j++) {
    temp = csYi[j];
    try {
     list.add((GlobalTestModel) listSYi.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   /**
   * 添加主观'偏易'的到list 中
   */
   for (int j = 0; j < sPianYi; j++) {
    temp = csPianYi[j];
    try {
     list.add((GlobalTestModel) listSPianYi.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   /**
   * 添加主观'中'的到list 中
   */
   for (int j = 0; j < sZhong; j++) {
    temp = csZhong[j];
    try {
     list.add((GlobalTestModel) listSZhong.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   /**
   * 添加主观'偏难'的到list 中
   */
   for (int j = 0; j < sPianNan; j++) {
    temp = csPianNan[j];
    try {
     list.add((GlobalTestModel) listSPianNan.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   for (int j = 0; j < sNan; j++) {
    temp = csNan[j];
    try {
     list.add((GlobalTestModel) listSNan.get(temp));
    } catch (Exception e) {
     System.out.println(e);
    }
   }

   // 将插销结果的关信息到Session中
   HttpSession session = request.getSession();
   // session.setAttribute(Constants.SESSION_USER, u);
   session.setAttribute(SystemConfig.SESSION_LIST, list);

   request.setAttribute('list', list);

   return mapping.findForward('make');

}

原创粉丝点击