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

项目地址(码云):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