package comdemo;
import javamathBigDecimal;
import javautilRandom;
import javautilScanner;
/
Java编写一个能够自动生成小朋友算术练习题目的程序。设计一个程序,要求能够随机生成每个题目。
编写一个能够自动生成小朋友算术练习题目的程序。设计一个程序,要求能够随机生成每个题目,并具有以下基本功能:
(1)要求题目以单项选择题及填空题两种形式出现。
(2)完成一题后自动判断答案是否正确,分别d出不同的提示,并自动更新成下一题。
(3)单击“退出”时,汇总本次计算结果,共完成几题,正确率,并给出相应评语。确定后正式退出。
/
public class publicDemo2 {
public static void main(String[] args) {
Random random = new Random();
StringBuilder stringBuilder = new StringBuilder();
String[] symbol = {"+","-","","/"};
String question_tip = "选择题(除法保留小数点后两位):";
stringBuilderappend(question_tip)append("\n");
Systemoutprintln(question_tip);
int a;
int b;
String f;
String result_str;
for (int i=1;i<11;i++){
a = randomnextInt(50);
b = randomnextInt(50);
f = symbol[randomnextInt(3)];
String question = i+"、"+a+f+b+"=";
Systemoutprintln(question);
stringBuilderappend(question);
Scanner sc = new Scanner(Systemin);
String sc_str = scnext();
if("/"equals(f)){
double scan_value = DoubleparseDouble(sc_str);
double result_value = a / b;
BigDecimal bigDecimal1 = new BigDecimal(scan_value);
scan_value = bigDecimal1setScale(2, BigDecimalROUND_HALF_UP)doubleValue();
BigDecimal bigDecimal2 = new BigDecimal(result_value);
result_value = bigDecimal2setScale(2, BigDecimalROUND_HALF_UP)doubleValue();
result_str = (scan_value==result_value)"回答正确!":"回答错误!";
stringBuilderappend(scan_value)append(";(答案:"+result_value+")"+result_str)append("\n");
}else{
int scan_value = IntegerparseInt(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)"回答正确!":"回答错误!";
stringBuilderappend(scan_value)append(";(答案:"+result_value+")"+result_str)append("\n");
}
}
Systemoutprintln(stringBuildertoString());
}
}
下午发
五分钟搞定,先给你发个简单的,照例子自己去做你想要的计算器
package aaa;
import javaawt;
import javaawtevent;
import javaxswing;
public class YunSuan implements ActionListener,ItemListener
{
public static JFrame jf;
public static Container c;
public static JTextField jtf1,jtf2,jtf3;
public static JButton jb1;
public static Choice c2;
public static String fuhao="";
public YunSuan()
{
jf=new JFrame("加减乘除运算");
c=jfgetContentPane();
csetLayout(new FlowLayout());
jtf1=new JTextField(10);
jtf2=new JTextField(10);
jtf3=new JTextField(10);
c2=new Choice();
jb1=new JButton("=");
}
public void Jiemian()
{
cadd(jtf1);
c2addItemListener(this);
c2add("");
c2add("+");
c2add("-");
c2add("");
c2add("/");
cadd(c2);
cadd(jtf2);
jb1addActionListener(this);
cadd(jb1);
cadd(jtf3);
jfsetLocation(200,100);
jfsetVisible(true);
jfpack();
}
public static void main(String args[])
{
YunSuan ys=new YunSuan();
ysJiemian();
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double s1=IntegerparseInt(jtf1getText());
double s2=IntegerparseInt(jtf2getText());
double result=0;
if(fuhaoequals("+"))
{
result=s1+s2;
String result2=StringvalueOf(result);
jtf3setText(result2);
}
if(fuhaoequals("-"))
{
result=s1-s2;
String result2=StringvalueOf(result);
jtf3setText(result2);
}
if(fuhaoequals(""))
{
result=s1s2;
String result2=StringvalueOf(result);
jtf3setText(result2);
}
if(fuhaoequals("/"))
{
result=s1/s2;
String result2=StringvalueOf(result);
jtf3setText(result2);
}
}
public void itemStateChanged(ItemEvent ie)
{
if(iegetSource()==c2)
{
String str1=c2getSelectedItem();
fanhui(str1);
}
}
public String fanhui(String str2)
{
return fuhao=str2;
}
}
public
MyCalculator()
{
f
=
new
JFrame("计算器ByMdou");
Container
contentPane
=
fgetContentPane();
/菜单的创建开始/
JMenuBar
mBar
=
new
JMenuBar();
mBarsetOpaque(true);
mEdit
=
new
JMenu("编辑(E)");
mEditsetMnemonic(KeyEventVK_E);
mCopy
=
new
JMenuItem("复制(C)");
mEditadd(mCopy);
mPaste
=
new
JMenuItem("粘贴(P)");
mEditadd(mPaste);
mView
=
new
JMenu("查看(V)");
mViewsetMnemonic(KeyEventVK_V);
mViewadd(new
JMenuItem("标准型"));
mViewadd(new
JMenuItem("科学型"));
mViewaddSeparator();
mViewadd(new
JMenuItem("查看分组"));
mHelp
=
new
JMenu("帮助(H)");
mHelpsetMnemonic(KeyEventVK_H);
mHelpadd(new
JMenuItem("帮助主题"));
mHelpaddSeparator();
mHelpadd(new
JMenuItem("关于计算器"));
mBaradd(mEdit);
mBaradd(mView);
mBaradd(mHelp);
fsetJMenuBar(mBar);
contentPanesetLayout(new
BorderLayout
());
JPanel
pTop
=
new
JPanel();
tResult
=
new
JTextField("0",26);
tResultsetHorizontalAlignment(JTextFieldRIGHT
);
tResultsetEditable(false);
pTopadd(tResult);
contentPaneadd(pTop,BorderLayoutNORTH);
JPanel
pBottom
=
new
JPanel();
pBottomsetLayout(new
BorderLayout());
JPanel
pLeft
=
new
JPanel();
pLeftsetLayout(new
GridLayout(5,1,3,3));
bM
=
new
JButton("
");
bMsetEnabled(false);
pLeftadd(bM);
bOther
=
new
JButton("MC");
bOtheraddActionListener(this);
bOthersetForeground(ColorRED);
bOthersetMargin(new
Insets(3,2,3,2));
pLeftadd(bOther);
bOther
=
new
JButton("MR");
bOtheraddActionListener(this);
bOthersetForeground(ColorRED);
bOthersetMargin(new
Insets(3,2,3,2));
pLeftadd(bOther);
bOther
=
new
JButton("MS");
bOtheraddActionListener(this);
bOthersetForeground(ColorRED);
bOthersetMargin(new
Insets(3,2,3,2));
pLeftadd(bOther);
bOther
=
new
JButton("M+");
bOtheraddActionListener(this);
bOthersetForeground(ColorRED);
bOthersetMargin(new
Insets(3,2,3,2));
pLeftadd(bOther);
import javautil;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(Systemin);
Systemoutprintln("简易计算器");
Systemoutprintln("\t\t\t\t\t");
Systemoutprintln(" 使用说明: 1加法 2减法 3乘法 4除法 ");
Systemoutprintln("\t\t\t\t\t");
Systemoutprintln("");
for(int i=0;i<100;i++){
Systemoutprint("\n请选择运算规则:");
int num = inputnextInt();
switch(num){
case 1:
Systemoutprintln("\n你选择了加法\n");
Systemoutprint("请输入第1个加数:");
int jiashu1 = inputnextInt();
Systemoutprint("请输入第2个加数:");
int jiashu2 = inputnextInt();
Systemoutprintln("运算结果为:" + jiashu1 + " + " + jiashu1 + " = " + (jiashu1 + jiashu2));
break;
case 2:
Systemoutprintln("\n你选择了减法\n");
Systemoutprint("请输入被减数:");
int jianshu1 = inputnextInt();
Systemoutprint("请输入减数:");
int jianshu2 = inputnextInt();
Systemoutprintln("运算结果为:" + jianshu1 + " - " + jianshu2 + " = " + (jianshu1 - jianshu2));
break;
case 3:
Systemoutprintln("\n你选择了乘法\n");
Systemoutprint("请输入第1个因数:");
int chengfa1 = inputnextInt();
Systemoutprint("请输入第2个因数:");
int chengfa2 = inputnextInt();
Systemoutprintln("运算结果为:" + chengfa1 + " " + chengfa2 + " = " + (chengfa1 chengfa2));
break;
case 4:
Systemoutprintln("\n你选择了除法\n");
Systemoutprint("请输入被除数:");
double chufa1 = inputnextInt();
Systemoutprint("请输入除数:");
double chufa2 = inputnextInt();
Systemoutprintln("运算结果为:" + chufa1 + " / " + chufa2 + " = " + (chufa1 / chufa2) + " 余 " + (chufa1 % chufa2));
break;
default:
Systemoutprintln("\n你的选择有错,请重新选择!");
break;
}
}
}
}
以上就是关于Java编写一个能够自动生成小朋友算术练习题目的程序。设计一个程序,要求能够随机生成每个题目。全部的内容,包括:Java编写一个能够自动生成小朋友算术练习题目的程序。设计一个程序,要求能够随机生成每个题目。、用Java设计一个图形界面(GUI)的计算器应用程序,完成简单的算术运算、求一个用JAVA编写的计算器程序(1)实现简单加、减、乘、除的运算。 (等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)