十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
import java.io.*;
网站设计制作、网站设计服务团队是一支充满着热情的团队,执着、敏锐、追求更好,是创新互联的标准与要求,同时竭诚为客户提供服务是我们的理念。成都创新互联公司把每个网站当做一个产品来开发,精雕细琢,追求一名工匠心中的细致,我们更用心!
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jdbc.driver.OracleDriver;
public class GenPaperServlet extends HttpServlet
{
Connection conn;
Statement stmt;
ResultSet rs;
int total_question_num;
int total_question_in_paper;
int total_paper_num;
String curr_classid;
public GenPaperServlet()
{
conn = null;
stmt = null;
rs = null;
total_question_num = 0;
total_question_in_paper = 0;
total_paper_num = 0;
curr_classid = "";
}
public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
httpservletresponse.setContentType("text/html;charset=GBK");
PrintWriter printwriter = httpservletresponse.getWriter();
printwriter.println("htmlhead/headbodycenter");
printwriter.println("请以POST方式提交");
printwriter.println("/center/body/html");
printwriter.close();
应该有规定是多少范围内整数吧 还有就是加减乘除吧 随机就用math.random()乘范围出数 然后取整 加减乘数也用随机数switch判断1234分别是加减乘除 倒数用timer和timertask类实现 那个手机的得响应一个向下获取焦点事件 类似的onKeyReleaseDown吧 下一个组件.setFocus 提交就是onSubmit事件 处理action或直接跳到ftl或者jsp上处理 传入结果参数程序分别判断下正确个数 然后显示就行了 正确率乘5就是分数
package com.demo;
import java.math.BigDecimal;
import java.util.Random;
import java.util.Scanner;
/*
* Java编写一个能够自动生成小朋友算术练习题目的程序。设计一个程序,要求能够随机生成每个题目。
* 编写一个能够自动生成小朋友算术练习题目的程序。设计一个程序,要求能够随机生成每个题目,并具有以下基本功能:
* (1)要求题目以单项选择题及填空题两种形式出现。
* (2)完成一题后自动判断答案是否正确,分别弹出不同的提示,并自动更新成下一题。
* (3)单击“退出”时,汇总本次计算结果,共完成几题,正确率,并给出相应评语。确定后正式退出。
*/
public class publicDemo2 {
public static void main(String[] args) {
Random random = new Random();
StringBuilder stringBuilder = new StringBuilder();
String[] symbol = {"+","-","*","/"};
String question_tip = "选择题(除法保留小数点后两位):";
stringBuilder.append(question_tip).append("\n");
System.out.println(question_tip);
int a;
int b;
String f;
String result_str;
for (int i=1;i11;i++){
a = random.nextInt(50);
b = random.nextInt(50);
f = symbol[random.nextInt(3)];
String question = i+"、"+a+f+b+"=";
System.out.println(question);
stringBuilder.append(question);
Scanner sc = new Scanner(System.in);
String sc_str = sc.next();
if("/".equals(f)){
double scan_value = Double.parseDouble(sc_str);
double result_value = a / b;
BigDecimal bigDecimal1 = new BigDecimal(scan_value);
scan_value = bigDecimal1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
BigDecimal bigDecimal2 = new BigDecimal(result_value);
result_value = bigDecimal2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
result_str = (scan_value==result_value)?"回答正确!":"回答错误!";
stringBuilder.append(scan_value).append(";(答案:"+result_value+")"+result_str).append("\n");
}else{
int scan_value = Integer.parseInt(sc_str);
int result_value;
if("+".equals(f)){
result_value = a + b;
}else if("-".equals(f)){
result_value = a - b;
}else if("*".equals(f)){
result_value = a * b;
}else{
break;
}
result_str = (scan_value==result_value)?"回答正确!":"回答错误!";
stringBuilder.append(scan_value).append(";(答案:"+result_value+")"+result_str).append("\n");
}
}
System.out.println(stringBuilder.toString());
}
}
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jdbc.driver.OracleDriver;
public class GenPaperServlet extends HttpServlet
{
Connection conn;
Statement stmt;
ResultSet rs;
int total_question_num;
int total_question_in_paper;
int total_paper_num;
String curr_classid;
public GenPaperServlet()
{
conn = null;
stmt = null;
rs = null;
total_question_num = 0;
total_question_in_paper = 0;
total_paper_num = 0;
curr_classid = "";
}
public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
httpservletresponse.setContentType("text/html;charset=GBK");
PrintWriter printwriter = httpservletresponse.getWriter();
printwriter.println("htmlhead/headbodycenter");
printwriter.println("请以POST方式提交");
printwriter.println("/center/body/html");
printwriter.close();
}
public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
httpservletresponse.setContentType("text/html;charset=GBK");
PrintWriter printwriter = httpservletresponse.getWriter();
String s = httpservletrequest.getParameter("classid"); //"20"
String s1 = httpservletrequest.getParameter("paper_num"); //"1"
if(s == null || s1 == null)
{
printwriter.println("center");
printwriter.println("请按照正常方式提交数据br");
printwriter.println("a href=/test/admin/genpaper.jsp单击这里设置生成试卷的参数/a");
printwriter.println("/center");
}
total_paper_num = Integer.parseInt(s1);
curr_classid = s;
int i = 0;
if(!open_db(curr_classid))
{
printwriter.println("打开数据库错误!");
return;
}
if(!setParams(curr_classid))
{
System.out.println("设置系统参数错误!");
return;
}
if(!verify_QuertionLib())
{
printwriter.println("试题库中试卷不足,请增加新的试题!");
printwriter.println("班级代号:" + curr_classid);
printwriter.println("该班级一套试卷中的试题数:" + total_question_in_paper);
printwriter.println("目前题库中该班级的试题总数:" + total_question_num);
return;
}
i = genPaper(total_paper_num, curr_classid);
if(i == 0)
{
printwriter.println("生成试卷操作失败!");
return;
}
if(!updateOtherTable(i, curr_classid))
{
printwriter.println("更新相关表操作失败!");
return;
} else
{
printwriter.println("center");
printwriter.println("动态组卷成功!br");
printwriter.println("共生成了 " + i + " 套试卷br");
printwriter.println("a href=/test/admin/genpaper.jsp单击这里设置生成试卷的参数/a");
printwriter.println("/center");
return;
}
}
public boolean open_db(String s)
{
try
{
new OracleDriver();
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ora9", "scott", "tiger");
stmt = conn.createStatement();
}
catch(Exception exception)
{
return false;
}
return true;
}
public boolean setParams(String s)
{
String s1 = "";
try
{
String s2 = "select count(questionid) as countquestionid from test_question_lib ";
s2 = s2 + "where classid='" + s + "'";
rs = stmt.executeQuery(s2);
rs.next();
total_question_num = rs.getInt("countquestionid");
s2 = "select totalques from test_classinfo ";
s2 = s2 + "where classid='" + s + "'";
rs = stmt.executeQuery(s2);
rs.next();
total_question_in_paper = rs.getInt("totalques");
}
catch(Exception exception)
{
return false;
}
return true;
}
public boolean verify_QuertionLib()
{
return total_question_num = total_question_in_paper;
}
public boolean updateOtherTable(int i, String s)
{
int j = 0;
String s1 = "update test_classinfo set totalpaper=totalpaper+";
s1 = s1 + i + " where classid='" + s + "'";
try
{
j = stmt.executeUpdate(s1);
}
catch(Exception exception)
{
return false;
}
return j == 1;
}
public int genPaper(int i, String s)
{
boolean flag = false;
boolean flag1 = false;
boolean flag2 = false;
boolean flag3 = false;
String s1 = "";
try
{
int ai[] = new int[total_question_num];
int i1 = 0;
boolean flag4 = false;
String s2 = "select max(paper_id) as max_paper_id from test_paper_lib";
rs = stmt.executeQuery(s2);
rs.next();
int j = rs.getInt("max_paper_id") + 1;
s2 = "select questionid from test_question_lib where classid='" + s + "'";
for(rs = stmt.executeQuery(s2); rs.next();)
ai[i1++] = rs.getInt("questionid");
for(int k1 = 0; k1 i; k1++)
{
int k = ai.length; //8
for(int l1 = 0; l1 total_question_in_paper; l1++)
{
// int ai[] ={1 ,3 , 5 ,9 , 56,30 96 ,25};
int j1 = (int)Math.floor(Math.random() * (double)k); // 4
String s3 = "insert into test_paper_lib values(";
s3 = s3 + "test_seq_paper.nextval," + j + "," + ai[j1] + ")";
stmt.executeUpdate(s3);
int l = ai[k - 1];
ai[k - 1] = ai[j1];
ai[j1] = l;
k--;
}
j++;
}
}
catch(Exception exception)
{
return 0;
}
return i;
}
}