由于刚接触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("你答错了! "+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+"题"+" "+"答错了"+w+"题"+" "+"正确率为"+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("你答错了! "+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+"题"+" "+"答错了"+w+"题"+" "+"正确率为"+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("你答错了! "+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+"题"+" "+"答错了"+w+"题"+" "+"正确率为"+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("你答错了! "+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+"题"+" "+"答错了"+w+"题"+" "+"正确率为"+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("你答错了! "+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+"题"+" "+"答错了"+w+"题"+" "+"正确率为"+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>
程序截图: