1. 程式人生 > >《結對-四則運算生成器-開發過程》

《結對-四則運算生成器-開發過程》

else n) 技術 編輯 exti dom class new void

項目地址(碼雲):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個運算符。

技術分享

基本效果如上



《結對-四則運算生成器-開發過程》