《结对-四则运算生成器-开发过程》

项目地址(码云):https://gitee.com/tdxm_bq/sizeyunsuan/

使用Android stdio编辑器

 

class Num {
private int max = 100;
private int min = 1;

public int getMin() {
return min;
}

public void setMin(int min) {
this.min = min;
}

public int getMax() {
return max;
}

public void setMax(int max) {
this.max = max;
}
public int shu(){
Random random = new Random();
int s = random.nextInt(max)%(max-min+1) + min;
return s;
}
public int fu(){
Random random = new Random();
int s = random.nextInt(4)%(4-1+1) + 1;
return s;
}
}
运算参数的随机生成部分单独创建了一个类来实现。
if(f == 1){
s1 = a.shu();
s2 = a.shu();
s3 = s1 + s2;
timu[0] = s1 + "+" +s2;
jieguo[0] = Double.toString(s3);
}else if(f == 2){
s1 = a.shu();
s2 = a.shu();
s3 = s1 - s2;
timu[0] = s1 + "-" +s2;
jieguo[0] = Double.toString(s3);
}else if(f == 3){
s1 = a.shu();
s2 = a.shu();
s3 = s1 * s2;
timu[0] = s1 + "*" +s2;
jieguo[0] = Double.toString(s3);
}else if(f == 4){
s1 = a.shu();
s2 = a.shu();
s3 = s1 / s2;
timu[0] = s1 + "/" +s2;
jieguo[0] = Double.toString(s3);
}
运算符用随机生成数字来实现1~4对应4个运算符。

基本效果如上



转载于:https://www.cnblogs.com/cxyliming/p/7630345.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值