import java.util.*;
import java.io.*;
//import java.Scanner;
class hu {
public double dui=0,cuo=0;
public void caidan1(){
System.out.println("************欢迎使用本计算系*************");
System.out.println("* 请选择您需要的服务种类 *");
System.out.println("* 1 整体测试 *");
System.out.println("* 2 单题测试 *");
System.out.println("* 3 成绩查询 *");
System.out.println("* 4 退出系统 *");
System.out.println("*****************************************");
}
public void caidan2(){
System.out.println("************欢迎使用本计算系*************");
System.out.println("* 请选择您需要的难度 *");
System.out.println("* 1 一位数运算 *");
System.out.println("* 2 两位数运算 *");
System.out.println("* 3 三位数运算 *");
System.out.println("* 4 退出系统 *");
System.out.println("*****************************************");
}
public void caidan3(){
System.out.println("************欢迎使用本计算系*************");
System.out.println("* 请选择您需要的运算方法 *");
System.out.println("* 1 加法运算 *");
System.out.println("* 2 减法运算 *");
System.out.println("* 3 乘法运算 *");
System.out.println("* 4 除法运算 *");
System.out.println("*****************************************");
}
public void caidan4(){
System.out.println("************欢迎使用本计算系*************");
System.out.println(" 过往成绩 ");
System.out.println(" 总共做了"+dui+cuo+"道题");
System.out.println(" 做对了"+dui+"道题");
System.out.println(" 做错了"+cuo+"道题");
System.out.println(" 正确率"+dui/(dui+cuo)+"%");
System.out.println("*****************************************");
}
public double shuru() throws IOException{ //输入数字
byte buf[]=new byte[40];
String chuan;
System.in.read(buf);
chuan=new String(buf);
return Double.parseDouble(chuan.trim());
/* double x;
Scanner scan=new Scanner;
String c=scan.next();
double x=Double.parseDouble(c);
return x;*/
}
double ysf()throws IOException{ //输入运算符
char ch;
double j=0;
for(int i=0;i<1000;i++){
ch=(char)System.in.read();
switch (ch){
case '+':
j=0;
break;
case '-':
j=1;
break;
case '*':
j=2;
break;
case '/':
j=3;
break;
default:
}
if (ch=='+'||ch=='-'||ch=='*'||ch=='/') break;
System.out.println("输入错误!!请重新输入:");
}
return j;
}
public static void main(String args[])throws IOException{
double b;
for (int i=0;i<1000;i++){
hu a=new hu();
a.caidan1(); //菜单1
b=a.shuru();
if (b==4) {
System.out.println("**********************");
System.out.println("* *");
System.out.println("* 感谢您的使用再见 *");
System.out.println("* *");
System.out.println("**********************");
break ;
} //输入
switch (b==1?1:b==2?2:b==3?3:4){
case 1:
hu a9=new hu();
a9.ztcs();
break;
case 2:
hu a8=new hu();
a8.dtcs();
break;
case 3:
hu a7=new hu();
a7.caidan4();
break;
default:
System.out.println("您的输入有误,请重试");
}
}
}
void guli(int a,int b){
if (b==0||a>1){
switch (a==2?1:a==3?2:a==4?3:a==5?4:a==6?5:6){
case 1:
System.out.println("不错不错连对了两道题值得鼓励!");
break;
case 2:
System.out.println("很好连对了三道题值得鼓励!");
break;
case 3:
System.out.println("厉害呀,连对了四道题了!");
break;
case 4:
System.out.println("哇塞!!都连对5道题了!!");
break;
case 5:
System.out.println("您做的不是题,是寂寞!~~");
break;
default:
}
}
else if(a==0||b>1){
switch (b==2?1:b==3?2:b==4?3:b==5?4:b==6?5:6){
case 1:
System.out.println("连错两道题了,别气馁");
break;
case 2:
System.out.println("连错了三道题了,别灰心");
break;
case 3:
System.out.println("连错四道题了,我都不知道怎么说你了~~");
break;
case 4:
System.out.println("都错五道题了,-_-!!");
break;
case 5:
System.out.println("贾君鹏!你快回家吧,别做题了~~");
break;
default:
}
}
System.out.println("***************");
}
double sjs (double a){
double i;
Random r=new Random();
switch (a==0?1:a==1?2:a==2?3:a==3?4:5){
case 1:
i=r.nextInt(10);
break;
case 2:
i=r.nextInt(90)+10;
break;
case 3:
i=r.nextInt(900)+100;
break;
case 4: //随即选择位数
i=r.nextInt(1000);
break;
default:
i=r.nextInt(4); //随即选择加减乘除
}
return i;
}
double chuti(double b,double c,double d){ //出题
hu p=new hu();
double daan;
char fuhao;
if (b==10||c==10){ // b=10 随机出 数
b=p.sjs(3);
c=p.sjs(3);
}
if (d==10) d=p.sjs(4); //d=10 随机出符号
switch (d==0?1:d==1?2:d==2?3:4){
case 1:
fuhao='+';
break;
case 2:
fuhao='-';
break;
case 3:
fuhao='*';
break;
default:
fuhao='/';
if(c==0) c=1;
}
daan=p.jisuan(b,c,d);
System.out.println(b+" "+fuhao+" "+c+"=");
return daan;
}
double jisuan(double a,double b,double c){ //计算
double daan=0;
if(c==0)daan=a+b;
else if(c==1)daan=a-b;
else if(c==2)daan=a*b;
else if(c==3)daan=a/b;
return daan;
}
void ztcs()throws IOException{ //整体测试
int y=0,n=0;
double c,d;
System.out.println("您选择了整体测试!");
System.out.println("我们会随机给您出10道题");
for (int i=0;i<11;i++){
System.out.println("请输入您的答案:");
hu a1=new hu();
hu a2=new hu();
hu a3=new hu();
c=a1.chuti(10,10,10);
System.out.println("daan="+c);
d=a2.shuru();
System.out.println("nishuru="+d);
if (d==c){
dui++;
y++;
n=0;
System.out.println("正确");
}
else{
y=0;
n++;
cuo++;
System.out.println("错误,答案是"+c);
}
a3.guli(y,n);
}
}
void dtcs()throws IOException{
double a,b,c,daan;
int y=0,n=0;
for (int i=0;i<1000;i++){
hu a4=new hu();
hu a5=new hu();
hu a6=new hu();
a4.caidan2();
a=a4.shuru(); //输入位数
if (a>3) break;
a5.caidan3();
b=a4.shuru(); //输入加减乘除
daan=a4.chuti(a,a,b);
System.out.println("请输入您的答案:");
c=a5.shuru();
if (c==daan){
dui++;
y++;
n=0;
System.out.println("正确");
}
else{
y=0;
n++;
cuo++;
System.out.println("错误,答案是"+daan);
}
a5.guli(y,n);
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Main extends JFrame {
private Vector
private String op = "+-*/";
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the frame
*/
public Main() {
super();
getContentPane().setLayout(null);
setBounds(100, 100, 224, 273);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
chuji();
}
});
button.setText("初级");
button.setBounds(39, 22, 106, 28);
getContentPane().add(button);
final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
zhongji();
}
});
button_1.setText("中级");
button_1.setBounds(39, 77, 106, 28);
getContentPane().add(button_1);
final JButton button_2 = new JButton();
button_2.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
gaoji();
}
});
button_2.setText("高级");
button_2.setBounds(39, 131, 106, 28);
getContentPane().add(button_2);
final JButton button_3 = new JButton();
button_3.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
jieguo();
}
});
button_3.setText("查看结果");
button_3.setBounds(39, 180, 106, 28);
getContentPane().add(button_3);
//
}
public void chuji() {
showDialog(10);
}
public void zhongji() {
showDialog(100);
}
public void gaoji() {
showDialog(1000);
}
public void jieguo(){
JDialog dialog = new JDialog(this,"结果");
dialog.setSize(400, 300);
JTextArea ta = new JTextArea();
for(String s : timu){
ta.append(s+"\n");
}
dialog.add(new JScrollPane(ta));
dialog.setVisible(true);
}
public void showDialog(int n){
Random random = new Random();
for(int i = 0 ; i < 5 ; i ++){
int a = random.nextInt(n);
char o = op.charAt(random.nextInt(4));
int b = random.nextInt(n);
if(o == '/' && (b == 0 || b > a)){
i--;
continue;
}
String res = JOptionPane.showInputDialog(this, ""+a+o+b);
if(res == null || "".equals(res))
res = "没有回答";
String s = ""+a+o+b+"="+res+" "+eval(a,b,o);
if(res.equals(eval(a,b,o)+"")){
s += "回答正确";
}else{
s += "回答错误";
}
timu.add(s);
}
jieguo();
}
public int eval(int a,int b,char o){
if(o == '+'){
return a + b;
}else if(o == '-')
return a - b ;
else if(o == '*')
return a * b ;
else
return a / b ;
}
}
要是有金钱报酬的话,给我发消息
你得说明 是基于B/S架构的还是C/S架构的
你比我还懒,我实训做的是计算器,记得给我加分啊,