日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

四则运算4

發(fā)布時(shí)間:2024/10/12 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 四则运算4 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

????? 這次編程主要是對我們之前編寫的C++四則運(yùn)算進(jìn)行移植,將其移植到安卓手機(jī)平臺,因?yàn)橹白龅氖荂++版本的,所以做起來饒了很多彎路,需要現(xiàn)將其改編為Java語言,在進(jìn)行后續(xù)工作。

????? 這個(gè)安卓程序我們命名為《易百分》,它主有三個(gè)Activity界面,第一個(gè)上邊輸入想要做的題目數(shù)量,用intent將其傳值道第二個(gè)Activity界面上,然后根據(jù)這些條件出題,每個(gè)題目由3-5個(gè)數(shù)組成,最后能算出答案并進(jìn)行比較,結(jié)束后會(huì)統(tǒng)計(jì)做對的題目數(shù)量,然后給出正確率。第三個(gè)界面則是對這個(gè)軟件的介紹了,如何使用和版本等信息。

????? 我們的代碼主要如下:????? 第一個(gè)布局文件:

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:background="@drawable/background" 6 android:orientation="vertical" > 7 8 <TextView 9 android:id="@+id/textView1" 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:layout_gravity="center" 13 android:layout_marginTop="40dp" 14 android:text="易百分" 15 android:textColor="#0000FF" 16 android:textSize="30dp" /> 17 18 <LinearLayout 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 android:layout_weight="0.02" 22 android:orientation="vertical" > 23 24 <TextView 25 android:id="@+id/textView2" 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:layout_gravity="center_horizontal" 29 android:layout_marginTop="30dp" 30 android:text="請輸入題目數(shù)量" 31 android:textSize="20sp" /> 32 33 <EditText 34 android:id="@+id/edtnumber" 35 android:layout_width="107dp" 36 android:layout_height="wrap_content" 37 android:layout_gravity="center" 38 android:layout_marginTop="10dp" 39 android:ems="10" 40 android:inputType="numberSigned" > 41 42 <requestFocus /> 43 </EditText> 44 45 <RadioGroup 46 android:id="@+id/radioGroup1" 47 android:layout_width="wrap_content" 48 android:layout_height="wrap_content" 49 android:layout_gravity="center" 50 android:layout_marginTop="20dp" > 51 52 <RadioButton 53 android:id="@+id/radio0" 54 android:layout_width="wrap_content" 55 android:layout_height="wrap_content" 56 android:checked="true" 57 android:text="一位數(shù)運(yùn)算" /> 58 59 <RadioButton 60 android:id="@+id/radio1" 61 android:layout_width="wrap_content" 62 android:layout_height="wrap_content" 63 android:layout_marginTop="10dp" 64 android:text="兩位數(shù)運(yùn)算" /> 65 66 </RadioGroup> 67 68 <Button 69 android:id="@+id/btnTijiao" 70 android:layout_width="123dp" 71 android:layout_height="wrap_content" 72 android:layout_gravity="center" 73 android:layout_marginTop="30dp" 74 android:onClick="onClickTijiao2" 75 android:text="提 交" /> 76 </LinearLayout> 77 78 </LinearLayout>

????? 這個(gè)界面對應(yīng)的Java文件:

1 package com.ml.caculate; 2 3 import android.app.Activity; 4 import android.app.AlertDialog; 5 import android.content.Intent; 6 import android.os.Bundle; 7 import android.view.ContextMenu; 8 import android.view.ContextMenu.ContextMenuInfo; 9 import android.view.View; 10 import android.widget.EditText; 11 import android.widget.RadioButton; 12 import android.widget.RadioGroup; 13 import android.widget.RadioGroup.OnCheckedChangeListener; 14 import android.widget.TextView; 15 16 public class page2 extends Activity { 17 18 TextView tv1; 19 EditText edtnum; 20 RadioButton mRadio1; 21 RadioButton mRadio2; 22 RadioGroup genderGroup; 23 String info="0"; 24 @Override 25 protected void onCreate(Bundle savedInstanceState) { 26 // TODO Auto-generated method stub 27 super.onCreate(savedInstanceState); 28 setContentView(R.layout.help2); 29 tv1=(TextView)findViewById(R.id.textView2); 30 edtnum=(EditText)findViewById(R.id.edtnumber); 31 mRadio1 = (RadioButton) findViewById(R.id.radio0); 32 mRadio2 = (RadioButton) findViewById(R.id.radio1); 33 genderGroup=(RadioGroup)findViewById(R.id.radioGroup1); 34 genderGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { 35 36 @Override 37 public void onCheckedChanged(RadioGroup group, int checkedId) { 38 // TODO Auto-generated method stub 39 if (checkedId == mRadio1.getId()) 40 { 41 info="0"; 42 } 43 else if (checkedId == mRadio2.getId()) 44 { 45 info="1"; 46 } 47 } 48 }); 49 50 51 } 52 53 @Override 54 public void onCreateContextMenu(ContextMenu menu, View v, 55 ContextMenuInfo menuInfo) { 56 // TODO Auto-generated method stub 57 58 super.onCreateContextMenu(menu, v, menuInfo); 59 } 60 61 public void onClickTijiao2(View v) 62 { 63 String S1=edtnum.getText().toString(); 64 if(S1.length()==0) //判斷輸入框是否為空 65 { 66 new AlertDialog.Builder(this) 67 .setTitle("提示信息") 68 .setMessage("您還沒有輸入數(shù)量") 69 .setPositiveButton("現(xiàn)在輸入", null) 70 .show(); 71 } 72 else 73 { 74 String R=info; //傳值表示式子類型 75 String number=edtnum.getText().toString(); 76 Intent intent=new Intent(); 77 intent.setClass(page2.this,MainActivity.class); 78 intent.putExtra("extra", number); //put傳到另一個(gè)界面 79 intent.putExtra("redio", R); //put傳到另一個(gè)界面 80 81 //啟動(dòng) 82 this.startActivity(intent); 83 } 84 85 } 86 87 88 }

?????? 第二個(gè)布局文件,也是實(shí)現(xiàn)主要功能的布局:

1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:id="@+id/LinearLayout1" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical" 7 android:paddingBottom="@dimen/activity_vertical_margin" 8 android:paddingLeft="@dimen/activity_horizontal_margin" 9 android:paddingRight="@dimen/activity_horizontal_margin" 10 android:paddingTop="@dimen/activity_vertical_margin" 11 tools:context=".MainActivity" > 12 13 <LinearLayout 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:layout_gravity="center" 17 android:gravity="center_vertical" 18 android:orientation="vertical" > 19 20 <TextView 21 android:id="@+id/textView1" 22 android:layout_width="wrap_content" 23 android:layout_height="wrap_content" 24 android:layout_gravity="center" 25 android:layout_marginTop="24dp" 26 android:text="小學(xué)生計(jì)算題" 27 android:textSize="26dp" /> 28 29 </LinearLayout> 30 31 <LinearLayout 32 android:layout_width="match_parent" 33 android:layout_height="wrap_content" 34 android:layout_marginTop="30dp" 35 android:gravity="center" > 36 37 <TextView 38 android:id="@+id/tvNum" 39 android:layout_width="wrap_content" 40 android:layout_height="wrap_content" 41 android:text="請" 42 android:textSize="20dp" /> 43 44 <TextView 45 android:id="@+id/tvSuanshi" 46 android:layout_width="wrap_content" 47 android:layout_height="wrap_content" 48 android:text="點(diǎn)擊下一題開始做題" 49 android:textSize="20sp" /> 50 51 </LinearLayout> 52 53 <LinearLayout 54 android:layout_width="110dp" 55 android:layout_height="wrap_content" 56 android:layout_gravity="center" 57 android:orientation="vertical" > 58 59 <TextView 60 android:id="@+id/textView4" 61 android:layout_width="wrap_content" 62 android:layout_height="wrap_content" 63 android:layout_marginTop="30dp" 64 android:text="輸入你的結(jié)果" 65 android:textSize="18dp" /> 66 67 <EditText 68 android:id="@+id/editText1" 69 android:layout_width="105dp" 70 android:layout_height="wrap_content" 71 android:layout_marginTop="20dp" 72 android:ems="10" 73 android:inputType="none" 74 android:text="" /> 75 76 </LinearLayout> 77 78 <LinearLayout 79 android:layout_width="200dp" 80 android:layout_height="wrap_content" 81 android:layout_gravity="center" 82 android:layout_marginTop="25dp" 83 android:onClick="onClickYes" > 84 85 <Button 86 android:id="@+id/btnYes" 87 android:layout_width="100dp" 88 android:layout_height="wrap_content" 89 android:onClick="onClickYes" 90 android:text="確 定" /> 91 92 <Button 93 android:id="@+id/btnClear" 94 android:layout_width="100dp" 95 android:layout_height="wrap_content" 96 android:onClick="ClearClick" 97 android:text="下一題" /> 98 99 </LinearLayout> 100 101 <TextView 102 android:id="@+id/textView2" 103 android:layout_width="wrap_content" 104 android:layout_height="wrap_content" 105 android:layout_gravity="center" 106 android:layout_marginTop="90dp" 107 android:text="版本號:V 15.04.0001" /> 108 109 </LinearLayout>

?????? 對應(yīng)的Java文件:

1 package com.ml.caculate; 2 3 4 import java.math.BigDecimal; 5 import java.util.Stack; 6 import android.os.Bundle; 7 import android.app.Activity; 8 import android.app.AlertDialog; 9 import android.content.DialogInterface; 10 import android.content.Intent; 11 import android.content.DialogInterface.OnClickListener; 12 import android.view.Menu; 13 import android.view.MenuItem; 14 import android.view.View; 15 import android.widget.EditText; 16 import android.widget.TextView; 17 18 public class MainActivity extends Activity { 19 20 /* (non-Javadoc) 21 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) 22 */ 23 24 25 @Override 26 public boolean onOptionsItemSelected(MenuItem item) { 27 // TODO Auto-generated method stub 28 int id=item.getItemId(); 29 30 if(id==R.id.action_settings) 31 { 32 Intent i = new Intent(MainActivity.this , page1.class); 33 //啟動(dòng)幫助說明界面 34 startActivity(i); 35 return true; 36 } 37 return super.onOptionsItemSelected(item); 38 39 } 40 41 TextView ss,suanshi,zhengque,nandu; 42 EditText edtResult; 43 int j=10; 44 boolean i=true; 45 int num=0; 46 String str=Way_1(); 47 int shumu=0; 48 49 int trr=0,err=0; 50 51 52 53 @Override 54 protected void onCreate(Bundle savedInstanceState) { 55 super.onCreate(savedInstanceState); 56 setContentView(R.layout.activity_main); 57 ss=(TextView)findViewById(R.id.tvNum); 58 zhengque=(TextView)findViewById(R.id.textView1); 59 nandu=(TextView)findViewById(R.id.textView4); 60 suanshi=(TextView)findViewById(R.id.tvSuanshi); 61 edtResult=(EditText)findViewById(R.id.editText1); 62 } 63 64 @Override 65 public boolean onCreateOptionsMenu(Menu menu) { 66 // Inflate the menu; this adds items to the action bar if it is present. 67 getMenuInflater().inflate(R.menu.main, menu); 68 ss.setText(""); 69 return true; 70 } 71 72 //產(chǎn)生算式的函數(shù) 73 private static int Operands_2() /*1-9*/ 74 { 75 int Operand=(int)(Math.random()*9)+1; 76 return Operand; 77 } 78 private static int Operands_3() /*1-99*/ 79 { 80 int Operand=(int)(Math.random()*99)+1; 81 return Operand; 82 } 83 private static String Operator_1(String formula)/*隨機(jī)產(chǎn)生運(yùn)算符 有乘除*/ 84 { 85 int f=(int)(Math.random()*4); 86 if(f==0) 87 { 88 formula+="+"; 89 } 90 if(f==1) 91 { 92 formula+="-"; 93 } 94 if(f==2) 95 { 96 formula+="*"; 97 } 98 if(f==3) 99 { 100 formula+="/"; 101 } 102 return formula; 103 } 104 private static String Way_1() /*最多可支持10個(gè)數(shù)參與計(jì)算 有乘除 有括號 10以內(nèi) 加減有負(fù)數(shù) 除法有余數(shù)*/ 105 { 106 String formula=""; 107 int length=(int)(Math.random()*1)+3; /*隨機(jī)產(chǎn)生表達(dá)式中操作數(shù)的個(gè)數(shù) 3-4 個(gè)*/ 108 int left=0,right=0,flag=0,left_1; 109 for(int i=0;i<length-1;i++) 110 { 111 left_1=left; 112 // left=Bracket_l(left,formula); 113 //--------- 114 int f=(int)(Math.random()*3); 115 if(f<2) 116 { 117 } 118 if(f==2) 119 { 120 formula+="("; 121 left++; 122 } 123 //****** 124 if(left_1!=left) /*產(chǎn)生了左括號 flag=i*/ 125 { 126 flag=i; 127 } 128 formula+=Operands_2(); 129 if(left>right&&flag!=i) /*左括號大于右括號的個(gè)數(shù) and 產(chǎn)生左括號和右括號不在一個(gè)循環(huán)里 即不會(huì)產(chǎn)生“(隨機(jī)數(shù))” 這種無效情況*/ 130 { 131 //right=Bracket_r(right,formula); 132 int r=(int)(Math.random()*5); 133 if(r==0) 134 { 135 } 136 if(r>0) /*產(chǎn)生右括號的概率大 */ 137 { 138 formula+=")"; 139 right++; 140 } 141 } 142 formula=Operator_1(formula); /*有乘除*/ 143 } 144 /*因?yàn)?一個(gè)操作數(shù)一個(gè)運(yùn)算符 還缺少一個(gè)操作數(shù) (0 -- 9)*/ 145 formula+=Operands_2(); 146 for(int i=0;i<left-right;i++) 147 { 148 formula+=")"; 149 } 150 return formula+="#"; 151 } 152 private static String Way_2() /* 有乘除 有括號 100以內(nèi) 加減有負(fù)數(shù) 除法有余數(shù)*/ 153 { 154 String formula=""; 155 int length=(int)(Math.random()*1)+3; /*隨機(jī)產(chǎn)生表達(dá)式中操作數(shù)的個(gè)數(shù)3-4 個(gè)*/ 156 int left=0,right=0,flag=0,left_1; 157 for(int i=0;i<length-1;i++) 158 { 159 left_1=left; 160 // left=Bracket_l(left,formula); 161 //--------- 162 int f=(int)(Math.random()*3); 163 if(f<2) 164 { 165 } 166 if(f==2) 167 { 168 formula+="("; 169 left++; 170 } 171 //****** 172 if(left_1!=left) /*產(chǎn)生了左括號 flag=i*/ 173 { 174 flag=i; 175 } 176 formula+=Operands_3(); 177 if(left>right&&flag!=i) /*左括號大于右括號的個(gè)數(shù) and 產(chǎn)生左括號和右括號不在一個(gè)循環(huán)里 即不會(huì)產(chǎn)生“(隨機(jī)數(shù))” 這種無效情況*/ 178 { 179 //right=Bracket_r(right,formula); 180 int r=(int)(Math.random()*5); 181 if(r==0) 182 { 183 } 184 if(r>0) /*產(chǎn)生右括號的概率大 */ 185 { 186 formula+=")"; 187 right++; 188 } 189 } 190 formula=Operator_1(formula); /*有乘除*/ 191 } 192 /*因?yàn)?一個(gè)操作數(shù)一個(gè)運(yùn)算符 還缺少一個(gè)操作數(shù) (0 -- 9)*/ 193 formula+=Operands_3(); 194 for(int i=0;i<left-right;i++) 195 { 196 formula+=")"; 197 } 198 return formula+="#"; 199 } 200 //---------------------------------------------- 201 static double jisuan(double x,double y,char oper) 202 { 203 switch(oper) 204 { 205 case '+': 206 { 207 return x+y; 208 } 209 case '-': 210 { 211 return x-y; 212 } 213 case '*': 214 { 215 return x*y; 216 } 217 case '/': 218 { 219 return x/y; 220 } 221 } 222 return 0; 223 } 224 225 static char precede(char ch1,char ch2) 226 { 227 int i = 0,j=0; 228 char[][] a={ //優(yōu)先級對照表,依次為+ - * / ( ) # 229 // + - * / ( ) # 230 {'>','>','<','<','<','>','>'}, // + 231 {'>','>','<','<','<','>','>'}, // - 232 {'>','>','>','>','<','>','>'}, // * 233 {'>','>','>','>','<','>','>'}, // / 234 {'<','<','<','<','<','=','0'}, // ( 235 {'>','>','>','>','0','>','>'}, // 236 {'<','<','<','<','<','0','='} // # 237 }; 238 switch(ch1) 239 { 240 //優(yōu)先級與矩陣匹配 241 case '+': 242 { 243 i=0; 244 break; 245 } 246 case '-': 247 { 248 i=1; 249 break; 250 } 251 case '*': 252 { 253 i=2; 254 break; 255 } 256 case '/': 257 { 258 i=3; 259 break; 260 } 261 case '(': 262 { 263 i=4; 264 break; 265 } 266 case ')': 267 { 268 i=5; 269 break; 270 } 271 case '#': 272 { 273 i=6; 274 break; 275 } 276 } 277 switch(ch2) 278 { 279 //優(yōu)先級與矩陣匹配 280 case '+': 281 { 282 j=0; 283 break; 284 } 285 case '-': 286 { 287 j=1; 288 break; 289 } 290 case '*': 291 { 292 j=2; 293 break; 294 } 295 case '/': 296 { 297 j=3; 298 break; 299 } 300 case '(': 301 { 302 j=4; 303 break; 304 } 305 case ')': 306 { 307 j=5; 308 break; 309 } 310 case '#': 311 { 312 j=6; 313 break; 314 } 315 } 316 return a[i][j]; 317 } 318 319 static double fun(String str) 320 { 321 double result = 0; 322 Stack<Character> optr = new Stack<Character> (); 323 Stack<Double> opnd = new Stack<Double>(); 324 //SqStack optr,opnd; //運(yùn)算符 操作數(shù) 325 //InitStack(optr); 326 //push(optr,'#'); 327 optr.push('#'); 328 //InitStack(opnd); 329 int length=str.length(); 330 int i=0; 331 char ch; 332 char s[] = str.toCharArray(); 333 ch=s[i]; 334 while(ch!='#'||optr.peek()!='#'&&i<length) 335 { 336 if(ch>='0'&&ch<='9') 337 { 338 char chh=s[++i]; 339 if(chh>='0'&&chh<='9') 340 { 341 double c=(ch-48)*10+chh-48; 342 opnd.push(c); 343 ch=s[++i]; 344 } 345 else 346 { 347 double c=ch-48; 348 opnd.push(c); 349 ch=chh; 350 } 351 352 } 353 else 354 switch(precede(optr.peek(),ch)){ 355 case '<': 356 { 357 //push(optr,ch); 358 optr.push(ch); 359 ch=s[++i]; 360 break; 361 } 362 case '>': 363 { 364 //double y=pop1(opnd); 365 //double x=pop1(opnd); 366 double y=opnd.pop(); 367 double x=opnd.pop(); 368 char c=optr.pop(); 369 result=jisuan(x,y,c); 370 //push1(opnd,result+48); 371 opnd.push(result); 372 break; 373 } 374 case '=': 375 { 376 //pop(optr); 377 optr.pop(); 378 ch=s[++i]; 379 break; 380 } 381 } 382 } 383 return result; 384 } 385 386 public void onClickYes(View v) //確定按鈕 387 { 388 Intent intent = getIntent(); 389 String nn=intent.getStringExtra("extra"); 390 int number=Integer.parseInt(nn); //從前一個(gè)界面?zhèn)鬟^來的值 391 if(shumu==number) 392 { 393 new AlertDialog.Builder(this) 394 .setTitle("提示信息") 395 .setMessage("您已經(jīng)做完"+number+"道題,共答對"+trr+"道題") 396 .setPositiveButton("OK", null) 397 .show(); 398 } 399 String S1=edtResult.getText().toString(); 400 if(ss.getText()=="請"||S1.length()==0) //判斷輸入框是否為空 401 { 402 new AlertDialog.Builder(this) 403 .setTitle("提示信息") 404 .setMessage("您還沒有輸入答案或還沒開始") 405 .setPositiveButton("現(xiàn)在輸入", null) 406 //.setNegativeButton("是", null) 407 .show(); 408 } 409 else 410 { 411 String str=ss.getText().toString(); 412 double result1 = fun(str); 413 BigDecimal bg = new BigDecimal(result1); 414 double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 415 // ss.setText(str); 416 double answer=Double.valueOf(edtResult.getText().toString()); 417 if (answer!=f1) 418 { 419 new AlertDialog.Builder(this) 420 .setTitle("錯(cuò)誤提示") 421 .setMessage("很遺憾 ,回答錯(cuò)誤!") 422 .setNegativeButton("下一題",new OnClickListener() { 423 424 @Override 425 public void onClick(DialogInterface arg0, int arg1) { 426 // TODO Auto-generated method stub 427 Intent intent = getIntent(); 428 String rr=intent.getStringExtra("redio"); 429 int red=Integer.parseInt(rr); 430 if(red==0) 431 { 432 String str=Way_1(); 433 ss.setText(str); 434 zhengque.setText("小學(xué)生計(jì)算題"); 435 suanshi.setText(" ?"); 436 } 437 else 438 { 439 String str=Way_1(); 440 ss.setText(str); 441 zhengque.setText("小學(xué)生計(jì)算題"); 442 suanshi.setText(" ?"); 443 } 444 } 445 }) 446 .show(); 447 shumu++; 448 } 449 else if(answer==f1) 450 { 451 suanshi.setText(" ?"); 452 zhengque.setText("恭喜回答正確!!!"); 453 ss.setText("請點(diǎn)擊下一道題,繼續(xù)..."); 454 trr++; 455 } 456 edtResult.setText(""); 457 } 458 } 459 460 public void ClearClick(View v) //下一題按鈕 461 462 { 463 Intent intent = getIntent(); 464 String nn=intent.getStringExtra("extra"); 465 String rr=intent.getStringExtra("redio"); 466 int number=Integer.parseInt(nn); //從前一個(gè)界面?zhèn)鬟^來的值 467 int red=Integer.parseInt(rr); 468 if(shumu<number) 469 { 470 edtResult.setText(""); 471 if(red==0) 472 { 473 String str=Way_1(); 474 ss.setText(str); 475 zhengque.setText("小學(xué)生計(jì)算題"); 476 suanshi.setText(" ?"); 477 shumu++; 478 } 479 else 480 { 481 String str=Way_2(); 482 ss.setText(str); 483 zhengque.setText("小學(xué)生計(jì)算題"); 484 suanshi.setText(" ?"); 485 shumu++; 486 } 487 } 488 else 489 { 490 new AlertDialog.Builder(this) 491 .setTitle("提示信息") 492 .setMessage("您已經(jīng)做完"+number+"道題,共答對"+trr+"道題") 493 .setPositiveButton("OK", null) 494 .show(); 495 ss.setText(""); 496 String s2=trr+"/"+number+"#"; 497 double s=fun(s2); 498 BigDecimal bg = new BigDecimal(s); 499 double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 500 suanshi.setText("正確率:"+f1*100+"%"); 501 } 502 } 503 } 504 505 506 507

????? 幫助說明布局文件:

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 7 <TextView 8 android:id="@+id/textView1" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:layout_gravity="center" 12 android:layout_marginTop="40dp" 13 android:text="幫助說明" 14 android:textSize="24dp" /> 15 16 <LinearLayout 17 android:layout_width="match_parent" 18 android:layout_height="wrap_content" 19 android:layout_marginTop="35dp" 20 android:orientation="vertical" > 21 22 <TextView 23 android:id="@+id/textView2" 24 android:layout_width="238dp" 25 android:layout_height="wrap_content" 26 android:layout_gravity="center" 27 android:layout_marginTop="16dp" 28 android:layout_weight="0.59" 29 android:text="1.您可以選擇題目數(shù)量。" 30 android:textSize="20dp" /> 31 32 <TextView 33 android:id="@+id/textView3" 34 android:layout_width="238dp" 35 android:layout_height="wrap_content" 36 android:layout_gravity="center" 37 android:layout_marginTop="16dp" 38 android:layout_weight="0.59" 39 android:text="2.您可以選擇有無乘除。" 40 android:textSize="20dp" /> 41 42 <TextView 43 android:id="@+id/textView4" 44 android:layout_width="238dp" 45 android:layout_height="wrap_content" 46 android:layout_gravity="center" 47 android:layout_marginTop="16dp" 48 android:layout_weight="0.59" 49 android:text="3.結(jié)果是小數(shù)的,保留兩位小數(shù)。" 50 android:textSize="20dp" /> 51 52 53 <TextView 54 android:id="@+id/textView5" 55 android:layout_width="238dp" 56 android:layout_height="wrap_content" 57 android:layout_gravity="center" 58 android:layout_marginTop="16dp" 59 android:layout_weight="0.59" 60 android:text="4.結(jié)果是整數(shù)的,保留一位小數(shù)。" 61 android:textSize="20dp" /> 62 63 <TextView 64 android:id="@+id/textView6" 65 android:layout_width="238dp" 66 android:layout_height="wrap_content" 67 android:layout_gravity="center" 68 android:layout_marginTop="16dp" 69 android:layout_weight="0.59" 70 android:text="5.預(yù)祝你取得好成績!" 71 android:textSize="20dp" /> 72 </LinearLayout> 73 74 <LinearLayout 75 android:layout_width="match_parent" 76 android:layout_height="wrap_content" 77 android:layout_marginTop="60dp" 78 android:gravity="center_horizontal" > 79 80 <TextView 81 android:id="@+id/textView7" 82 android:layout_width="wrap_content" 83 android:layout_height="wrap_content" 84 android:layout_gravity="center" 85 android:text="版本號:" /> 86 87 <TextView 88 android:id="@+id/textView8" 89 android:layout_width="wrap_content" 90 android:layout_height="wrap_content" 91 android:text="V 15.04.0001" /> 92 </LinearLayout> 93 94 <LinearLayout 95 android:layout_width="match_parent" 96 android:layout_height="wrap_content" 97 android:gravity="center_horizontal"> 98 99 <TextView 100 android:id="@+id/textView9" 101 android:layout_width="wrap_content" 102 android:layout_height="wrap_content" 103 android:layout_marginTop="10dp" 104 android:text="關(guān)注博客園:_小學(xué)生and小青年" /> 105 106 </LinearLayout> 107 108 </LinearLayout>

????? 對應(yīng)的Java文件:

1 package com.ml.caculate; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.os.Bundle; 6 import android.view.ContextMenu; 7 import android.view.ContextMenu.ContextMenuInfo; 8 import android.view.View; 9 import android.widget.RadioButton; 10 import android.widget.RadioGroup; 11 import android.widget.TextView; 12 13 public class page1 extends Activity { 14 15 public RadioGroup rg; 16 public RadioButton mRadio1, mRadio2,mRadio3; 17 String []info=new String [3]; 18 TextView tv1; 19 20 @Override 21 protected void onCreate(Bundle savedInstanceState) { 22 // TODO Auto-generated method stub 23 super.onCreate(savedInstanceState); 24 setContentView(R.layout.help); 25 tv1=(TextView)findViewById(R.id.textView1); 26 } 27 28 @Override 29 public void onCreateContextMenu(ContextMenu menu, View v, 30 ContextMenuInfo menuInfo) { 31 // TODO Auto-generated method stub 32 super.onCreateContextMenu(menu, v, menuInfo); 33 } 34 35 public void onClickTijiao1(View v) 36 { 37 Intent i = new Intent("android.intent.action.PAGE2"); 38 i.putExtra(info[0], info[0]); 39 //啟動(dòng) 40 startActivity(i); 41 } 42 }

????? ? 運(yùn)行效果:

?

?

??????? 這次試驗(yàn)有很多細(xì)節(jié)的地方,比如判空語句,比如判斷對錯(cuò)的對話框,光判空語句就占了將近1/4的代碼量,做完了這個(gè)小軟件,有一點(diǎn)小小的成就感。

項(xiàng)目計(jì)劃總結(jié):???
日期聽課編寫程序查閱資料日總計(jì)
星期一?2226
星期二????
星期三?314
星期四?22?4
星期五?2?2
星期六?314
星期日?314
周總計(jì)?17724

???????

時(shí)間記錄日志:?????
日期開始時(shí)間結(jié)束時(shí)間中斷時(shí)間凈時(shí)間活動(dòng)備注
4月1日14:0016:1010120編寫編程修改程序
4月2日8:2010:4030110編寫程序將程序改為Java語言
4月3日16:3020:3030210查閱資料查資料和調(diào)試
4月4日15:0021:401003000編程修改和調(diào)試
4月5日10:0017:30903600調(diào)試最終調(diào)試
4月6日18:0018:30?30博客撰寫博客

???????

缺陷記錄日志:
日期編號引入階段排除階段調(diào)試過程中遇到的BUG以及解決辦法
4月1日1編碼編譯對C++的四則運(yùn)算進(jìn)行了修改,變?yōu)镴ava語言
4月2日2編碼編譯在安卓里邊,每次都在判斷下一個(gè)結(jié)果,修改執(zhí)行順序。
4月3日3編碼編譯判斷時(shí),為了不出現(xiàn)循環(huán)小數(shù),我們保留兩位小數(shù)。
4月4日4編碼編譯問題帶“#”輸出,讓其在計(jì)算的時(shí)候加“#”,輸出時(shí)沒有。
4月4日5編碼編譯加入了一個(gè)新界面,用來獲取用戶輸入的題目數(shù)量和難度。
4月6日6編碼編譯頁面之間傳值過不去,仔細(xì)看了一下怎樣用Intent傳參,問題解決。

??????? 小伙伴博客地址:http://www.cnblogs.com/L-Damon-v/

??????? 點(diǎn)擊此鏈接下載App易百分

轉(zhuǎn)載于:https://www.cnblogs.com/cnyulei/p/5360840.html

總結(jié)

以上是生活随笔為你收集整理的四则运算4的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 色综合av | 色婷婷av一区二区三区软件 | 好妞色妞国产在线视频 | 女同久久另类69精品国产 | 午夜成人免费视频 | 美女毛毛片 | 激情五月在线 | 精品综合久久 | 黄色小视频链接 | 91在线无精精品入口 | 国产精品视频一区在线观看 | 射射色 | 色婷婷av一区二区三区在线观看 | 亚洲国产剧情在线观看 | 国产小视频在线观看免费 | 亚洲欧美国产高清va在线播放 | 黄色国产在线 | 爱情岛论坛永久入口 | 国产成人在线免费观看视频 | 在线不卡欧美 | 东北少妇不带套对白 | 国产亚洲精品熟女国产成人 | 黄页视频在线观看 | 永久免费在线 | 成人av资源在线 | 68日本xxxxxⅹxxx22 | 绯色av一区二区 | 亚洲再线| 黄色一级在线 | 激情婷婷在线 | 波多野结衣中文一区 | 日韩精品色哟哟 | 放荡闺蜜高h苏桃情事h | 爱插美女网 | 国产精品一区二区三区四区在线观看 | 999热视频 | 深夜福利网站在线观看 | 免费看黄色片子 | 国产无码日韩精品 | 国产永久av | 欧美日韩一区三区 | 国产一区二区三区在线视频观看 | 91精东传媒理伦片在线观看 | 国产美女免费看 | 顶级尤物极品女神福利视频 | 好屌妞视频这里只有精品 | 亚洲AV无码国产精品国产剧情 | 免费日韩一区 | 艳妇臀荡乳欲伦交换在线播放 | av专区在线 | 中文字幕超清在线免费观看 | 亚洲精品激情视频 | 中国大陆一级毛片 | 色婷婷综合久久 | 成人av第一页 | 午夜宅男影院 | 欧美午夜激情视频 | 日韩av一区在线 | 污污视频在线看 | 欧美日韩福利视频 | 日韩第三页 | 黄色片网站免费观看 | 婷婷综合激情网 | 99久久久无码国产精品性波多 | 欧美色国 | 精品国产乱码久久久久久图片 | 欧洲日韩一区二区三区 | 黄色一级片一级片 | 老头吃奶性行交 | av大帝在线观看 | 一级黄色免费 | 成人激情免费视频 | 日韩制服在线 | 男人狂揉女人下部视频 | 中文字幕视频一区 | 借种(出轨高h) | 高清一区二区三区四区五区 | 日本午夜免费 | 久久久久久久久久网 | 性一交一乱一乱一视频 | 日韩精品一线二线三线 | 激情自拍偷拍 | 99久久精品国产一区二区成人 | 伊人网综合| 国产九九精品 | 国产老妇伦国产熟女老妇视频 | 亚洲成网站 | 久久久久国产精品一区 | av电影在线不卡 | 成年人视频免费 | 丁香综合 | jiizzyou性欧美老片 | 在线一二区 | 制服丝袜第一页在线观看 | 成人欧美视频在线观看 | 成人免费看片视频 | 亚洲专区一区 | 色播av | 欧美色综合网站 |