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

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

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

本次发布已经解决上次问题,问题是写程序逻辑错误,问题已经修改!我们还增加两个模块的面板设置,如下是程序结果:

import java.util.Random;

import android.os.Bundle;
import android.app.Activity;
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 char[] ch = {'+','-','*','/'}; //字符数组
	private int index = r.nextInt(ch.length); //随机数,小于数组的长度数, 0~3
	private char a=ch[index];
	private TextView text1,text2,text3;
	private EditText answer;
	private Button surebutton;//确定按钮
	//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);
		text1=(TextView)findViewById(R.id.textView1);//随机数字
		text2=(TextView)findViewById(R.id.textView2);//运算符号
		text3=(TextView)findViewById(R.id.textView3);//随机数字
		answer=(EditText)findViewById(R.id.editText1);//运算结果
		final String c=String.valueOf(num1.nextInt(100));
		i2=Integer.valueOf(c);
		final String d=String.valueOf(a);
		final 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();
					else
						Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
					break;
				}
				case 1:
				{
					if(i1==(i2-i3))
						Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
					else
						Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
					break;
				}
				case 2:{
					if(i1==(i2*i3))
						Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
					else
						Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
					break;		
				}
				case 3:
				{
					if(i3!=0){
					if(i1==(i2/i3))
						Toast.makeText(CalculatorActivity.this, "正确"+b, Toast.LENGTH_SHORT).show();
					else
						Toast.makeText(CalculatorActivity.this, "错误"+b, Toast.LENGTH_SHORT).show();
					}
					break;
				}
				}
			}
		});
		
	}

	@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;
	}

}

 

新功能选择页面代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="23dp"
        android:text="@string/title_activity_choice"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="33dp"
        android:text="TextView"
        android:textSize="20sp" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/title"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="44dp" >

        <RadioButton
            android:id="@+id/R1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="20sp" />

        <RadioButton
            android:id="@+id/R2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="20sp" />

        <RadioButton
            android:id="@+id/R3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="20sp" />

        <RadioButton
            android:id="@+id/R4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="20sp" />
    </RadioGroup>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/radioGroup1"
        android:layout_marginTop="34dp"
        android:text="下一题" />

</RelativeLayout>

 

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="35dp"
        android:text="@string/title_activity_set"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignLeft="@+id/textView1"
        android:ems="10"
        android:inputType="number" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="41dp"
        android:layout_toLeftOf="@+id/editText1"
        android:text="@string/the_number_of_calculator"
        android:textSize="20sp" />

    <RadioButton
        android:id="@+id/radioButton4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/radioButton3"
        android:layout_alignBottom="@+id/radioButton3"
        android:layout_marginLeft="25dp"
        android:layout_toRightOf="@+id/textView1"
        android:text="/" />

    <RadioButton
        android:id="@+id/radioButton3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/radioButton2"
        android:layout_alignBottom="@+id/radioButton2"
        android:layout_alignRight="@+id/textView1"
        android:layout_marginRight="18dp"
        android:text="*" />

    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/radioButton1"
        android:layout_alignBottom="@+id/radioButton1"
        android:layout_toRightOf="@+id/textView2"
        android:text="-" />

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="16dp"
        android:text="+" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView3"
        android:layout_toLeftOf="@+id/radioButton3"
        android:layout_toRightOf="@+id/textView3"
        android:ems="10"
        android:inputType="number" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/radioButton3"
        android:text="分"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/radioButton1"
        android:layout_below="@+id/radioButton1"
        android:layout_marginTop="58dp"
        android:text="时间设置:"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView4"
        android:layout_alignRight="@+id/radioButton4"
        android:layout_marginLeft="16dp"
        android:layout_toRightOf="@+id/textView4"
        android:ems="10"
        android:inputType="number" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView4"
        android:layout_alignBottom="@+id/textView4"
        android:layout_alignParentRight="true"
        android:text="秒" 
        android:textSize="20sp"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/editText2"
        android:layout_marginTop="43dp"
        android:text="确定" />

</RelativeLayout>