团队成员:陈淑筠、杨家安、陈曦

团队选题:小学四则运算APP

第一次冲刺阶段时间:11.17~11.27

本次发布的是完成的功能一:

程序代码:

MainActivity代码:

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	
	private Button xunlian;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		xunlian=(Button)findViewById(R.id.button1);
		xunlian.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent=new Intent();
				intent.setClass(MainActivity.this, CalculatorSet.class);
				startActivity(intent);
				MainActivity.this.finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

 Calculatorset代码:

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	
	private Button xunlian;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		xunlian=(Button)findViewById(R.id.button1);
		xunlian.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent=new Intent();
				intent.setClass(MainActivity.this, CalculatorSet.class);
				startActivity(intent);
				MainActivity.this.finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

 calculatoractivity代码:

import java.util.Random;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class CalculatorActivity extends Activity {
	private final Random num1=new Random();
	private final Random num2=new Random();
	private final Random r = new Random();
	private Button next;
	private char[] ch = {'+','-','*','/'};//字符数组
	//private int[]puanduan;
	private int index; //随机数,小于数组的长度数, 0~3
	private char a;
	private TextView text1,text2,text3;
	private EditText answer;
	private Button surebutton;//确定按钮
	private int i,m=0;
	private String c;
	private String e;
	private String b;
	private int i1,i2,i3;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_calculator);
		Bundle bundle=getIntent().getExtras();
		index=bundle.getInt("suanfa");
		a=ch[index];
		i=bundle.getInt("shumu");
		final String[]puanduan=new String[i];
		text1=(TextView)findViewById(R.id.textView1);//随机数字
		text2=(TextView)findViewById(R.id.textView2);//运算符号
		text3=(TextView)findViewById(R.id.textView3);//随机数字
		answer=(EditText)findViewById(R.id.editText1);//运算结果
		next=(Button)findViewById(R.id.next);
		String c=String.valueOf(num1.nextInt(100));
		i2=Integer.valueOf(c);
		String d=String.valueOf(a);
		String e=String.valueOf(num2.nextInt(100));
		i3=Integer.valueOf(e);
		text1.setText(c);//随机数1-100
		text2.setText(d);//随机运算符+,-,*,/
		text3.setText(e);//随机数1-100
		surebutton=(Button)findViewById(R.id.surebutton);//确定按钮
		surebutton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				final String b=answer.getText().toString();//获取输入的数值
				i1=Integer.valueOf(b);
				switch(index){
				case 0:
				{
					if(i1==(i2+i3))
					{
						Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
						puanduan[m]="正确";
					}
					else
					{
						Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
						puanduan[m]="错误";
					}
					break;
				}
				case 1:
				{
					if(i1==(i2-i3))
					{
						Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
						puanduan[m]="正确";
					}
					else
					{
						Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
						puanduan[m]="错误";
					}
					break;
				}
				case 2:{
					if(i1==(i2*i3))
					{
						Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
						puanduan[m]="正确";
					}
					else
					{
						Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
						puanduan[m]="错误";
					}
					break;		
				}
				case 3:
				{
					if(i3!=0){
					if(i1==(i2/i3))
					{
						Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
						puanduan[m]="正确";
					}
					else
					{
						Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
						puanduan[m]="错误";
					}
					}
					break;
				}
				}
				i--;
				m++;
				if(i==0){
					Toast.makeText(CalculatorActivity.this,"已经到了了题目个数!",Toast.LENGTH_LONG ).show();
					
				}
				else{
					String c=String.valueOf(num1.nextInt(100));
					i2=Integer.valueOf(c);
					String d=String.valueOf(a);
					String e=String.valueOf(num2.nextInt(100));
					i3=Integer.valueOf(e);
					text1.setText(c);//随机数1-100
					text2.setText(d);//随机运算符+,-,*,/
					text3.setText(e);//随机数1-100	
					answer.setText(null);
				}
			}
		});
		next.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(i==0){
				Intent intent=new Intent();
				Bundle bundle2=new Bundle();
				bundle2.putStringArray("panduan", puanduan);
				bundle2.putInt("number", m);
				intent.putExtras(bundle2);
				intent.setClass(CalculatorActivity.this,resultActivity.class);
				startActivity(intent);
				CalculatorActivity.this.finish();
				}
				else
					Toast.makeText(CalculatorActivity.this,"不到题目个数,请继续", Toast.LENGTH_LONG).show();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.calculator, menu);
		return true;
	}

}

 resultActivity代码:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class resultActivity extends Activity {
	private TextView number;
	private TextView panduan;
	//private TextView sum;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_result);
		Bundle bundle=getIntent().getExtras();
		number=(TextView)findViewById(R.id.thenumber);
		panduan=(TextView)findViewById(R.id.pan);
		 int i=bundle.getInt("number");
		 String []puanduan=bundle.getStringArray("panduan");
		 String aa="";
		 String aaa="";
		for(int g=0;g<i;g++){
			aa+=String.valueOf(g+1)+"\n";
			aaa+=puanduan[g]+"\n";
			number.setText(aa);
			panduan.setText(aaa);;
		}
		}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

 运行结果: