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

📄 tools.java

📁 培训考试系统代码
💻 JAVA
字号:
package com.huawei.icd30.agt.util;

import java.util.Random;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * <p> 本类为业务代表管理系统的工具类。</p>
 * <p> </p>
 * <p> </p>
 * @author 龙燕茜
 * @version 1.0
 */

public class Tools
{



    private Tools()
    {
    }

    /**
     * 获取字符数组的集合,以"#"号分隔
     * @return
     */
    public static String getStringSet(String[] strArr)
    {
        if(strArr == null)
        {
           return null;
        }
        String strSet = "";
        strSet = strArr[0];
        for(int i=1; i<strArr.length; i++)
        {
           strSet += "#" + strArr[i];
        }
        return strSet;
    }

    /**
     * 对试题的选项进行随机排序
     * @return
     * */
    public static void randOrderOption(String option,ArrayList desOption,
                  ArrayList desOptionKey)
    {
        //定义抽取的对象
        Random rdm = new Random();
        //源试题选项的个数
        int srcCount = countCharacter(option,"#");
        ArrayList srcOption = new ArrayList(srcCount);
        ArrayList srcOptionKey = new ArrayList(srcCount);
        String[] optionKeySet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N",
        "O","P","Q","R","S","T","U","V","W","X","Y","Z"};

        int i = 0;
        StringTokenizer stoken = new StringTokenizer(option,"#");
        while(stoken.hasMoreTokens())
        {
            srcOption.add(stoken.nextToken());
            srcOptionKey.add(optionKeySet[i]);
            i++;
        }

        int count = srcCount;
        //循环进行抽取
        for(i=0; i<count; i++)
        {
             //随机抽取(按位置)
             int loc = rdm.nextInt(srcCount);

             //对应插入位置为loc对象到desTestIdArr与desTestScoreArr中
             desOption.add(srcOption.get(loc));
             desOptionKey.add(srcOptionKey.get(loc));

             //从srcTestIdArr与srcTestScoreArr中把位置为loc的对象删除
             srcOption.remove(loc);
             srcOptionKey.remove(loc);

             srcCount = srcCount - 1;
        }
    }

    /**
     * 计算一字符串str包含字符串cstr的个数
     * @param str
     * @param cstr
     */
    public static int countCharacter(String str,String cstr)
    {
       int count = 0;
       for(int i=0;i<str.length();i++)
       {
          String tmpStr = str.substring(i,i+1);
          if(tmpStr.equalsIgnoreCase(cstr))
          {
             count++;
          }
       }
       count++;
       return count;
    }

}

⌨️ 快捷键说明

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