zoukankan      html  css  js  c++  java
  • 软件工程结对作业02

    四则运算(4)

    一、程序要求

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

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

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

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

      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等控件的使用由不熟悉到熟练运用,也是废了不少功夫的。至于没有实现的功能,如果有机会,我会进一步完善它。

    六、工作照片

    小伙伴:张莹荧(http://www.cnblogs.com/zhyying/

  • 相关阅读:
    静态工具类中使用注解注入service
    赵伟国:芯片不像互联网 不能一招鲜吃遍天(发展芯片制造业已拥有三个纵深:市场纵深、资本纵深、人才纵深)
    将grub写入mbr
    Linux下Qt5.6 Fcitx无法输入中文输入解决办法
    为 Mac Finder 增加右键文件打包压缩(免费)
    Obtaining Directory Change Notifications(微软的例子,使用FindFirstChangeNotification,FindNextChangeNotification,FindCloseChangeNotification API函数)
    C#开发Linux守护进程
    排序算法比较与分析
    Mvc+Dapper+存储过程分页10万条数据
    RabbitMQ
  • 原文地址:https://www.cnblogs.com/Aliqiao/p/5360552.html
Copyright © 2011-2022 走看看