您的位置:首页 > 其它

软件工程结对作业02

2016-04-06 18:36 387 查看

四则运算(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/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: