续.第一次冲刺之后.
第一次冲刺:
每个员可以各自完成自己的分配好的模块
罗伟业:加减算术----乘除算式 返回一个完整正确(加减、乘除)的算式<考虑到低年级还没有完全掌握四则混合运算>
康取:四则混合运算算式 返回一个完整正确的混合四种运算的算式 <含分数>
陈键:四则混合+括号混合 返回一个完整正确的混合四种运算的算式 <含分数>
现在也基本达到了目标 .
基本能够达到预想效果< UI - 。-不堪入目 有待提高.>
在完成过程中想到了
----存储 一些默认设置 比如模式和难度的选择等等的数据
-----增加一个对题 错题的 比较.分数显示.
-----设置输入内容只能是数值 。不能是分数,保留三位小数.<规划输入格式>
1 package com.example.testc; 2 import java.math.BigDecimal; 3 import java.util.Random; 4 import android.app.Activity; 5 import android.os.Bundle; 6 import android.view.View; 7 public class MainActivity extends Activity { 8 private Calculator calculator = new Calculator(); 9 private Double intemp ; 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 setContentView(R.layout.activity_main); 14 } 15 public void onclick(View v) { 16 switch (v.getId()) { 17 case R.id.createone: 18 String a = createOperation(); 19 calculator.setExpression(a); 20 adjustResult( calculator.getResult() ,"1"); 21 System.out.println(a + "===" +intemp+ "====" + calculator.getResult()); 22 break; 23 } 24 } 25 26 /** 比较答案的对错,精度为0.001 **/ 27 public boolean adjustResult(String CorrectResult, String userResult) { 28 BigDecimal correctAnswer = new BigDecimal(CorrectResult); 29 BigDecimal userAnswer = new BigDecimal(userResult); 30 double cAnswer; 31 double uAnswer; 32 33 cAnswer = correctAnswer.doubleValue(); 34 uAnswer = userAnswer.doubleValue(); 35 int ax = (int) Math.round(cAnswer * 1000) ; 36 cAnswer = ax /1000.0; 37 intemp=cAnswer; 38 if (Math.abs(cAnswer - uAnswer) < 0.001 ) 39 return true; 40 return false; 41 } 42 43 public String createOperation() { 44 Random seed = new Random(); 45 final String ADD = "+" + ""; 46 final String MINUS = "-" + ""; 47 final String MULTIPLY = "x" + ""; 48 final String DEVIDE = "/" + ""; 49 50 // 操作数的个数.而且最多为五个,默认三个操作数 51 int number = 3; 52 String datas[] = new String[5]; 53 String op[] = new String[5]; 54 55 /** 生成 操作数个数 **/ 56 int numberSeeder = seed.nextInt(4) + 1; 57 58 if (numberSeeder == 1) 59 number = 3; 60 else if (numberSeeder == 2 || numberSeeder == 4) 61 number = 4; 62 else if (numberSeeder == 3) 63 number = 5; 64 65 /** 生成 操作数 跟 符号 **/ 66 for (int i = 0; i < number; i++) { 67 int jud = seed.nextInt(100); 68 if (jud < 20) { 69 datas[i] = fraction(); 70 } else if (jud < 100) { 71 datas[i] = integerCreater(); 72 } 73 if (i<number-1) { 74 /** 操作数的个数都是比符号的个数多一个 **/ 75 int judp= seed.nextInt(4) + 1; 76 if (judp == 1) 77 op[i] = ADD; 78 else if (judp == 2) 79 op[i] = MINUS; 80 else if (judp == 3) 81 op[i] = MULTIPLY; 82 else if (judp== 4) 83 op[i] = DEVIDE; 84 } 85 } 86 return createBrackets(datas, op, number); 87 } 88 /** create an integer **/ 89 public String integerCreater() { 90 Random seed = new Random(); 91 String data; 92 data = String.valueOf(seed.nextInt(300) + 1); 93 return data; 94 } 95 /** create a fraction **/ 96 public String fraction() { 97 final String DEVIDE = "/" + ""; 98 final String leftear = "(" + ""; 99 final String rightear = ")" + ""; 100 int First = 1, second = 1; 101 Random seeder = new Random(); 102 First = seeder.nextInt(20) + 1;// 分子 103 second = seeder.nextInt(20) + 1;// 分母 104 return leftear + First + DEVIDE + second + rightear; 105 } 106 107 /** brackets block 操作数据数组 、 操作符 、 个数 **/ 108 public String createBrackets(String datas[], String operator[], int number) { 109 final String leftear = "(" + ""; 110 final String rightear = ")" + ""; 111 Random seeder = new Random(); 112 String bracketOperation = null; 113 switch (number) { 114 case 3: 115 if (seeder.nextInt() / 2 == 0) 116 bracketOperation = leftear + datas[0] + operator[0] + datas[1] 117 + rightear + operator[1] + datas[2]; 118 else 119 bracketOperation = datas[0] + operator[0] + leftear + datas[1] 120 + operator[1] + datas[2] + rightear; 121 break; 122 case 4: 123 int temp = seeder.nextInt(21) + 1; 124 temp = temp % 7 + 1; 125 switch (temp) { 126 case 1:// (a+b)x(a+b) 127 bracketOperation = leftear + datas[0] + operator[0] + datas[1] 128 + rightear + operator[1] + leftear + datas[2] 129 + operator[2] + datas[3] + rightear; 130 break; 131 case 2:// ((a+b)+b)+b 132 bracketOperation = leftear + leftear + datas[0] + operator[0] 133 + datas[1] + rightear + operator[1] + datas[2] 134 + rightear + operator[2] + datas[3]; 135 break; 136 case 3:// (a+(a+b))+b 137 bracketOperation = leftear + datas[0] + operator[0] + leftear 138 + datas[1] + operator[1] + datas[2] + rightear 139 + rightear + operator[2] + datas[3]; 140 break; 141 case 4:// (a+b)+a+b 142 bracketOperation = leftear + datas[0] + operator[0] + datas[1] 143 + rightear + operator[1] + datas[2] + operator[2] 144 + datas[3]; 145 break; 146 case 5:// a+b+(a+b) 147 bracketOperation = datas[0] + operator[0] + datas[1] 148 + operator[1] + leftear + datas[2] + operator[2] 149 + datas[3] + rightear; 150 break; 151 case 6:// a+(a+b)+b 152 bracketOperation = datas[0] + operator[0] + leftear + datas[1] 153 + operator[1] + datas[2] + rightear + operator[2] 154 + datas[3]; 155 break; 156 case 7:// (a+b+c)+a 157 bracketOperation = leftear + datas[0] + operator[0] + datas[1] 158 + operator[1] + datas[2] + rightear + operator[2] 159 + datas[3]; 160 break; 161 } 162 break; 163 case 5: 164 int dicision = seeder.nextInt(33) + 1; 165 dicision = dicision % 9 + 1; 166 switch (dicision) { 167 case 1:// (a+(a+b))+a+b 168 bracketOperation = leftear + datas[0] + operator[0] + leftear 169 + datas[1] + operator[1] + datas[2] + rightear 170 + rightear + operator[2] + datas[3] + operator[3] 171 + datas[4]; 172 break; 173 case 2:// ((a+b)+a)+a+a 174 bracketOperation = leftear + leftear + datas[0] + operator[0] 175 + datas[1] + rightear + operator[1] + datas[2] 176 + rightear + operator[2] + datas[3] + operator[3] 177 + datas[4]; 178 break; 179 case 3:// (a+b)x(a+b)+a 180 bracketOperation = leftear + datas[0] + operator[0] + datas[1] 181 + rightear + operator[1] + leftear + datas[2] 182 + operator[2] + datas[3] + rightear + operator[3] 183 + datas[4]; 184 break; 185 case 4:// (a+b)x(a+b+a) 186 bracketOperation = leftear + datas[0] + operator[0] + datas[1] 187 + rightear + operator[1] + leftear + datas[2] 188 + operator[2] + datas[3] + operator[3] + datas[4] 189 + rightear; 190 break; 191 case 5:// (a+b)x(a+b+c) 192 bracketOperation = leftear + datas[0] + operator[0] + datas[1] 193 + rightear + operator[1] + leftear + datas[2] 194 + operator[2] + datas[3] + operator[3] + datas[4] 195 + rightear; 196 break; 197 case 6:// (a+b)+a+(a+b) 198 bracketOperation = leftear + datas[0] + operator[0] + datas[1] 199 + rightear + operator[1] + datas[2] + operator[2] 200 + leftear + datas[3] + operator[3] + datas[4] 201 + rightear; 202 break; 203 case 7:// ((a+b)+a)X(a+b) 204 bracketOperation = leftear + leftear + datas[0] + operator[0] 205 + datas[1] + rightear + operator[1] + datas[2] 206 + rightear + operator[2] + leftear + datas[3] 207 + operator[3] + datas[4] + rightear; 208 break; 209 case 8:// (((a+b)+c)+d)+e 210 bracketOperation = leftear + leftear + leftear + datas[0] 211 + operator[0] + datas[1] + rightear + operator[1] 212 + datas[2] + rightear + operator[2] + datas[3] 213 + rightear + operator[3] + datas[4]; 214 break; 215 case 9:// a+(a+b+c)+e 216 bracketOperation = datas[0] + operator[0] + leftear + datas[1] 217 + operator[1] + datas[2] + operator[2] + datas[3] 218 + rightear + operator[3] + datas[4]; 219 break; 220 } 221 break; 222 } 223 return bracketOperation; 224 } 225 226 }
做真正的自己,活出别人没有的快乐。