一、程序要求

  1、生成的题目中计算过程不能产生负数,也就是说算术表达式中如果存在形如e1 − e2的子表达式,那么e1 ≥ e2。

  2、生成的题目中如果存在形如e1 ÷ e2的子表达式,那么其结果应是真分数。

  3、每道题目中出现的运算符个数不超过3个,括号不限。

  4、程序一次运行生成的题目不能重复,即任何两道题目不能通过有限次交换+和×左右的算术表达式变换为同一道题目。

    例如,23 + 45 = 和45 + 23 = 是重复的题目,6 × 8 = 和8 × 6 = 也是重复的题目。

    3+(2+1)和1+2+3这两个题目是重复的,由于+是左结合的,1+2+3等价于(1+2)+3,也就是3+(1+2),也就是3+(2+1)。

    但是1+2+3和3+2+1是不重复的两道题,因为1+2+3等价于(1+2)+3,而3+2+1等价于(3+2)+1,它们之间不能通过有限次交换变成同一个题目。

  5、把程序变成一个网页程序、智能手机程序、具有可操作界面的单机版程序三种之一, 用户通过设定参数,就可以得到各种题目,并可实现在线答题并评判。

二、程序设计思想

  根据前三个实验,将其改编为Eclipse开发的andriod app。

三、源程序代码

//主要代码
    public void btnSure_Click(View v){
        int sign,j;
        int fanwei,chengchu,yushu,fushu;
        int first,second,firstm,secondm;
        String s2="",s3="",s4="",s5="";
        s2=edtWidth.getText().toString();
           s3=edtCcf.getText().toString();
        s4=edtYushu.getText().toString();
        s5=edtFushu.getText().toString();
        fanwei=Integer.parseInt(s2);//范围
         chengchu=Integer.parseInt(s3);//乘除法
         yushu=Integer.parseInt(s4);//余数
        fushu=Integer.parseInt(s5);//负数
        
        j=ran.nextInt(2);
        if(j==0)           //选择整数
        {
            first=ran.nextInt(fanwei+1);
            second=ran.nextInt(fanwei+1);
            if(chengchu==1)
            {
                sign=ran.nextInt(4); 
            }
            else
            {
                sign=ran.nextInt(2);
            }
            switch(sign)
            {
            case 0:                      //整数加法
                tvTimu.setText("题目:"+first+"+"+second+"=");
                break;
            case 1:                      //整数减法
                if(fushu==1)
                {
                    tvTimu.setText("题目:"+first+"-"+second+"=");
                }
                else
                {
                    if(first>second)
                    {
                        tvTimu.setText("题目:"+first+"-"+second+"=");
                    }
                    else
                    {
                        tvTimu.setText("题目:"+second+"-"+first+"=");
                    }
                }
                break;
            case 2:                   //整数乘法
                tvTimu.setText("题目:"+first+"*"+second+"=");
                break; 
            case 3:                   //整数除法
                if(yushu==1)
                {
                    if(second!=0)
                    {
                        tvTimu.setText("题目:"+first+"/"+second+"=");
                    }
                }
                else
                {
                    if(second!=0&&(first%second==0))
                    {
                        tvTimu.setText("题目:"+first+"/"+second+"=");
                    }
                }
                    break;
            }
        }
        else              //选择分数
        {
            first=ran.nextInt(fanwei+1);
            second=ran.nextInt(fanwei+1);//分子
            firstm=ran.nextInt(fanwei+1);
            secondm=ran.nextInt(fanwei+1);//分母
            if(chengchu==1)
            {
                sign=ran.nextInt(4);
            }
            else
            {
                sign=ran.nextInt(2);
            }

            switch(sign)
            {
            case 0:                //分数加法
                if(firstm!=0&&secondm!=0&&first<firstm&&second<secondm)
                {
                    tvTimu.setText("题目:"+first+"/"+firstm+" + "+second+"/"+secondm+"=");
                }
                break;
            case 1:                //分数减法
                if(fushu==1)
                {
                    if(firstm!=0&&secondm!=0&&first<firstm&&second<secondm)
                    {
                        tvTimu.setText("题目:"+first+"/"+firstm+" - "+second+"/"+secondm+"=");
                    }
                }
                else
                {
                    if(firstm!=0&&secondm!=0&&first<firstm&&second<secondm&&(first/firstm)>(second/secondm))
                    {
                        tvTimu.setText("题目:"+first+"/"+firstm+" - "+second+"/"+secondm+"=");
                    }
                }
                break;
            case 2:                //分数乘法
                if(firstm!=0&&secondm!=0&&first<firstm&&second<secondm)
                {
                    tvTimu.setText("题目:"+first+"/"+firstm+" * "+second+"/"+secondm+"=");
                }
                break;
            case 3:                //分数除法
                if(firstm!=0&&secondm!=0&&first!=0&&second!=0&&first<firstm&&second<secondm)
                {
                    tvTimu.setText("题目:"+first+"/"+firstm+" / "+second+"/"+secondm+"=");
                }
                break;
            }
        }
    }

四、运行结果截图

  

  

  

 

五、心得体会

  在这次app编程中,我的收获很大。自己所学的安卓知识也得到了充分的应用。虽然有的功能没有实现,但是通过实验学到了很多其他课上学不到的东西。实现过程中虽然出现了不少的问题,但经过我和队友的不懈努力,最终解决了这些问题;button、textview等控件的使用由不熟悉到熟练运用,也是废了不少功夫的。至于没有实现的功能,如果有机会,我会进一步完善它。

 

六、结对开发队友 

  李俏 信1301-2班 20132912
  博客地址:http://www.cnblogs.com/Aliqiao/
  工作照: