制作一个可供小学数学运算程序:10以内加减法,能根据输入题数出题,判断做题是否正确,最后计算分数。 界面要求:美观简洁
- 提问者网友:我没有何以琛的痴心不悔
- 2021-05-02 08:05
- 五星知识达人网友:我住北渡口
- 2021-05-02 08:11
- 1楼网友:山河有幸埋战骨
- 2021-05-02 09:00
jp.add(jtf);
jtf.setBounds(120,10,40,20);
jp.add(jb);
jb.setBounds(10,50,60,40);
jp.add(jb2);
jb2.setBounds(80,50,60,40);
jp.add(jl2);
jl2.setBounds(60,100,200,50);
jf.setVisible(true);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public void produce() {
Random rand = new Random();
num1 = (int) (Math.random() * 100);
num2 = (int) (Math.random() * 100);
sum = 0;
temp = (int) (Math.random() * 10) % 2;
if (temp == 0) {
jl.setText("
第
"+(count)+"
题:
"+num1 + "+" + num2 + "=");
count++;
sum = num1 + num2;
} else {
count++;
jl.setText("
第
"+(count)+"
题:
"+num1 + "-" + num2 + "=");
sum = num1 - num2;
}
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int s = Integer.parseInt(jtf.getText());
if(s==sum){
jl2.setText("
恭喜,回答正确!
");
score += 10;
}else{
jl2.setText("
抱歉,回答错误。
"+"
正确答案:
" + sum);
}
}
}
);
jb2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(count==10){
JOptionPane j= new JOptionPane();
j.showMessageDialog(jf, "
您的得分是:
"+score);
jf.setVisible(false);
}
Random rand = new Random();
num1 = (int) (Math.random() * 100);
num2 = (int) (Math.random() * 100);
sum = 0;
temp = (int) (Math.random() * 10) % 2;
if (temp == 0) {
count++;
jl.setText("
第
"+(count)+"
题:
"+num1 + "+" + num2 + "=");
sum = num1 + num2;
} else {
count++;
jl.setText("
第
"+(count)+"
题:
"+num1 + "-" + num2 + "=");
sum = num1 - num2;
}
}
}
);
}
public static void main(String args[]) {
Random_problem a = new Random_problem();
a.produce();
}
}