由於剛接觸android-app的開發,很多問題都解決不了,連搭建環境都花了一個多星期才能解決,所以用了兩週才完成了第一個Spring計劃,在此要感謝大為同學的幫助才解決了android開發環境的搭建。
目前程式只有一個簡單(渣渣)的介面和最基本的運算功能,在寫程式的時候突然想到小學生可能想加強自己薄弱的演算法,就加了單項練習這個方面的功能(只是將本來的演算法功能拆分了,而且造成了程式碼重複,這個問題以後再改善),現在的程式還有很多小問題,比如當沒有輸入答案是按按鈕會使程式出錯自動退出等,這些問題也會在後續的編寫中完善。
一開始接觸android開發時根本不理解.java和res檔案中layout檔案中的.xml檔案之間是如何關聯起來了,最後是通過慕課網(http://www.imooc.com/)視訊學習開始瞭解android開發的一些思路。
貢獻分:
25鄭澤成:3.5
38李天麟:3
39吳梓健:10
40鍾鵬升:3.5
程式碼:
src
package com.example.szys; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { Button start,end; int yourChose=-1; private void showSinChosDia() { final String[] mList={"普通","困難(未進行)","加法練習","減法練習","乘法練習","除法練習"}; yourChose=-1; AlertDialog.Builder sinChosDia=new AlertDialog.Builder(MainActivity.this); sinChosDia.setTitle("難度/單項練習"); sinChosDia.setSingleChoiceItems(mList, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub yourChose=which; } }); sinChosDia.setPositiveButton("確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub if(yourChose==0) { Intent intent = new Intent(MainActivity.this, CalActivity.class); startActivity(intent); } if(yourChose==1) { /*Intent intent = new Intent(MainActivity.this, CalActivity2.class); startActivity(intent);*/ } if(yourChose==2) { Intent intent = new Intent(MainActivity.this, CalActivity2.class); startActivity(intent); } if(yourChose==3) { Intent intent = new Intent(MainActivity.this, CalActivity3.class); startActivity(intent); } if(yourChose==4) { Intent intent = new Intent(MainActivity.this, CalActivity4.class); startActivity(intent); } if(yourChose==5) { Intent intent = new Intent(MainActivity.this, CalActivity5.class); startActivity(intent); } } }); sinChosDia.create().show(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); start=(Button) findViewById(R.id.button1); start.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub showSinChosDia(); } }); end=(Button) findViewById(R.id.button3); end.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub System.exit(0); } }); } }
package com.example.szys; import java.math.*; import java.util.Random; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class CalActivity extends Activity { int op; int a; int b; int n=0; int w=0; String r; Double answer,respon; TextView textview1,textview2; EditText editText; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cal_main); textview1=(TextView)findViewById(R.id.textView1); textview2=(TextView)findViewById(R.id.textView2); editText=(EditText)findViewById(R.id.EditText1); a =new Random().nextInt(100); b =new Random().nextInt(100); op=new Random().nextInt(4); switch(op) { case 0: textview1.setText(a+"+"+b+"="); answer=(double) (a+b); break; case 1: textview1.setText(a+"-"+b+"="); answer=(double) (a-b); break; case 2: textview1.setText(a+"*"+b+"="); answer=(double) (a*b); break; case 3: while(b==0){ b =new Random().nextInt(100); } textview1.setText(a+"/"+b+"="); BigDecimal x = new BigDecimal((double)a/b); answer = x.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); break; } button=(Button)findViewById(R.id.button4); button.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub respon=Double.parseDouble(editText.getText().toString()); r=textview1.getText().toString(); editText.setText(""); n++; if(respon.equals(answer)) { textview2.setText("你答對了!"); } else{ w++; textview2.setText("你答錯了!\n"+r+answer); } if(n<5) { a =new Random().nextInt(100); b =new Random().nextInt(100); op=new Random().nextInt(4); switch(op) { case 0: textview1.setText(a+"+"+b+"="); answer=(double) (a+b); break; case 1: textview1.setText(a+"-"+b+"="); answer=(double) (a-b); break; case 2: textview1.setText(a+"*"+b+"="); answer=(double) (a*b); break; case 3: while(b==0){ b =new Random().nextInt(100); } textview1.setText(a+"/"+b+"="); BigDecimal x = new BigDecimal((double)a/b); answer = x.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); break; } } else { int right=n-w; double rvate=(double)right/n*100; AlertDialog.Builder builder = new AlertDialog.Builder(CalActivity.this); builder.setTitle("結束"); builder.setMessage("你答對了"+right+"題"+"\n"+"答錯了"+w+"題"+"\n"+"正確率為"+rvate+"%"); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent intent = new Intent(CalActivity.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); builder.create().show(); } } }); } }
package com.example.szys; import java.math.*; import java.util.Random; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class CalActivity2 extends Activity { int a; int b; int n=0; int w=0; String r; Double answer,respon; TextView textview1,textview2; EditText editText; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cal_main); textview1=(TextView)findViewById(R.id.textView1); textview2=(TextView)findViewById(R.id.textView2); editText=(EditText)findViewById(R.id.EditText1); a =new Random().nextInt(100); b =new Random().nextInt(100); textview1.setText(a+"+"+b+"="); answer=(double) (a+b); button=(Button)findViewById(R.id.button4); button.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub respon=Double.parseDouble(editText.getText().toString()); r=textview1.getText().toString(); editText.setText(""); n++; if(respon.equals(answer)) { textview2.setText("你答對了!"); } else{ w++; textview2.setText("你答錯了!\n"+r+answer); } if(n<5) { a =new Random().nextInt(100); b =new Random().nextInt(100); textview1.setText(a+"+"+b+"="); answer=(double) (a+b); } else { int right=n-w; double rvate=(double)right/n*100; AlertDialog.Builder builder = new AlertDialog.Builder(CalActivity2.this); builder.setTitle("結束"); builder.setMessage("你答對了"+right+"題"+"\n"+"答錯了"+w+"題"+"\n"+"正確率為"+rvate+"%"); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent intent = new Intent(CalActivity2.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); builder.create().show(); } } }); } }
package com.example.szys; import java.math.*; import java.util.Random; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class CalActivity3 extends Activity { int a; int b; int n=0; int w=0; String r; Double answer,respon; TextView textview1,textview2; EditText editText; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cal_main); textview1=(TextView)findViewById(R.id.textView1); textview2=(TextView)findViewById(R.id.textView2); editText=(EditText)findViewById(R.id.EditText1); a =new Random().nextInt(100); b =new Random().nextInt(100); textview1.setText(a+"-"+b+"="); answer=(double) (a-b); button=(Button)findViewById(R.id.button4); button.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub respon=Double.parseDouble(editText.getText().toString()); r=textview1.getText().toString(); editText.setText(""); n++; if(respon.equals(answer)) { textview2.setText("你答對了!"); } else{ w++; textview2.setText("你答錯了!\n"+r+answer); } if(n<5) { a =new Random().nextInt(100); b =new Random().nextInt(100); textview1.setText(a+"-"+b+"="); answer=(double) (a-b); } else { int right=n-w; double rvate=(double)right/n*100; AlertDialog.Builder builder = new AlertDialog.Builder(CalActivity3.this); builder.setTitle("結束"); builder.setMessage("你答對了"+right+"題"+"\n"+"答錯了"+w+"題"+"\n"+"正確率為"+rvate+"%"); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent intent = new Intent(CalActivity3.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); builder.create().show(); } } }); } }
package com.example.szys; import java.math.*; import java.util.Random; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class CalActivity4 extends Activity { int a; int b; int n=0; int w=0; String r; Double answer,respon; TextView textview1,textview2; EditText editText; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cal_main); textview1=(TextView)findViewById(R.id.textView1); textview2=(TextView)findViewById(R.id.textView2); editText=(EditText)findViewById(R.id.EditText1); a =new Random().nextInt(100); b =new Random().nextInt(100); textview1.setText(a+"*"+b+"="); answer=(double) (a*b); button=(Button)findViewById(R.id.button4); button.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub respon=Double.parseDouble(editText.getText().toString()); r=textview1.getText().toString(); editText.setText(""); n++; if(respon.equals(answer)) { textview2.setText("你答對了!"); } else{ w++; textview2.setText("你答錯了!\n"+r+answer); } if(n<5) { a =new Random().nextInt(100); b =new Random().nextInt(100); textview1.setText(a+"*"+b+"="); answer=(double) (a*b); } else { int right=n-w; double rvate=(double)right/n*100; AlertDialog.Builder builder = new AlertDialog.Builder(CalActivity4.this); builder.setTitle("結束"); builder.setMessage("你答對了"+right+"題"+"\n"+"答錯了"+w+"題"+"\n"+"正確率為"+rvate+"%"); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent intent = new Intent(CalActivity4.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); builder.create().show(); } } }); } }
package com.example.szys; import java.math.*; import java.util.Random; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class CalActivity5 extends Activity { int a; int b; int n=0; int w=0; String r; Double answer,respon; TextView textview1,textview2; EditText editText; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cal_main); textview1=(TextView)findViewById(R.id.textView1); textview2=(TextView)findViewById(R.id.textView2); editText=(EditText)findViewById(R.id.EditText1); a =new Random().nextInt(100); b =new Random().nextInt(100); while(b==0){ b =new Random().nextInt(100); } textview1.setText(a+"/"+b+"="); BigDecimal x = new BigDecimal((double)a/b); answer = x.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); button=(Button)findViewById(R.id.button4); button.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub respon=Double.parseDouble(editText.getText().toString()); r=textview1.getText().toString(); editText.setText(""); n++; if(respon.equals(answer)) { textview2.setText("你答對了!"); } else{ w++; textview2.setText("你答錯了!\n"+r+answer); } if(n<5) { a =new Random().nextInt(100); b =new Random().nextInt(100); while(b==0){ b =new Random().nextInt(100); } textview1.setText(a+"/"+b+"="); BigDecimal x = new BigDecimal((double)a/b); answer = x.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); } else { int right=n-w; double rvate=(double)right/n*100; AlertDialog.Builder builder = new AlertDialog.Builder(CalActivity5.this); builder.setTitle("結束"); builder.setMessage("你答對了"+right+"題"+"\n"+"答錯了"+w+"題"+"\n"+"正確率為"+rvate+"%"); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent intent = new Intent(CalActivity5.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); builder.create().show(); } } }); } }
res--->layout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center"> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="開始" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="歷史資料(未進行)" /> <Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="退出" /> </LinearLayout> </FrameLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" > <TextView android:id="@+id/textView1" android:layout_width="93dp" android:layout_height="wrap_content" android:editable="true" android:text="" /> <EditText android:id="@+id/EditText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:digits="1234567890.-" android:ems="10" android:numeric="decimal" android:text="" > <requestFocus /> </EditText> </LinearLayout> <Button android:id="@+id/button4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="確定" /> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="70dp" android:editable="true" android:text="" /> </LinearLayout> </LinearLayout>
程式截圖: