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

📄 managequestion.java

📁 考试系统 实现在线考试中的各项操作的源代码
💻 JAVA
字号:
package com.exam;

import java.util.*;

public class ManageQuestion 
{
	private static int number=0;                   //进行题目号的标注
	private static int aValue,rValue,bValue;       //两个操作数和正确的结果
	private static String uValue,r;                //用户所答的结果
	private static String fhValue;                 //操作符
	private static List list=new ArrayList();      //用于存储题目的数组
	
	//得到操作符
	public static String getFuHao(int indext)
	{
		String s=null;
		switch(indext)
		{
			case 1: s="+";break;
			case 2: s="-";break;
			case 3: s="*";break;
			case 4: s="/";break;
		}
		return s;
	}
	//得到当前所出题目的个数
	public static int getId()
	{
		return number;
	}
	//设置题目的答案
	public static void setUserAnswer(String r,int num)
	{
		Iterator iter=list.iterator();
		while(iter.hasNext())
		{
			QuestionBasic qq=(QuestionBasic)iter.next();
			if(qq.getId()==num)
				qq.setUserResult(r);
		}
		return;
	}
	//得到正确的结果
	public static String getRightAnswer(int num)
	{
		String m="";
		Iterator iter=list.iterator();
		while(iter.hasNext())
		{
			QuestionBasic qq=(QuestionBasic)iter.next();
			if(qq.getId()==num)
				m=qq.getResult();
				//return qq.getResult();
		}
		return m;
	}
	//获得一道题对应的答案
	public static String getUserAnswer(int num)
	{
		String m="";
		Iterator iter=list.iterator();
		while(iter.hasNext())
		{
			QuestionBasic qq=(QuestionBasic)iter.next();
			if(qq.getId()==num)
				m=qq.getUserResult();
				//return qq.getUserResult();
		}
		return m;
	}
	//获得一道题的题目
	public static String getQuestion(int num)
	{
		Iterator iter=list.iterator();
		while(iter.hasNext())
		{
			QuestionBasic qq=(QuestionBasic)iter.next();
			if(qq.getId()==num)
				return qq.getA()+qq.getFont()+qq.getB();
		}
		return "";
	}
	//加载符号,两个操作数,和正确结果
	public static void setQuestion()
	{
		uValue="34";
		int a=(int)(Math.random()*4)+1;
		number++;
		fhValue=getFuHao(a);
		switch(a)
		{
		//加法运算
		case 1:{
			aValue=(int)(Math.random()*50+1);
			int t=(int)(Math.random()*60+1);
			if(t<aValue)
			{
				int temp=aValue;
				aValue=t;
				t=temp;
				bValue=t-aValue;
				rValue=aValue+bValue;
			}
			else
				rValue=aValue+bValue;
		}break;	
		//减法运算
		case 2:{
			aValue=(int)(Math.random()*50+1);
			bValue=(int)(Math.random()*50+1);
			if(aValue<bValue)
			{
				int temp=aValue;
				aValue=bValue;
				bValue=temp;
			}
			rValue=aValue-bValue;	
		}break;
		//乘法运算
		case 3:{
			bValue=(int)(Math.random()*10+1);
			aValue=((int)(Math.random()*10)*bValue)/bValue;
			rValue=aValue*bValue;
		}break;
		//除法运算
		case 4:{
			bValue=(int)(Math.random()*10+1);
			aValue=(int)(Math.random()*10)*bValue;
			rValue=aValue/bValue;	
		}break;
		}
		r=rValue+"";
		QuestionBasic q=new QuestionBasic(aValue,fhValue,bValue,r,uValue,number);
		list.add(q);
	}
}

⌨️ 快捷键说明

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