zoukankan      html  css  js  c++  java
  • 小学四则运算APP 第二阶段冲刺-第五天

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

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

    第二次冲刺阶段时间:11.29~12.09

    本次发布的是判断题代码,已经实现部分功能,,但是美中不足的是判断错误

    panduanset.java

    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.RadioGroup.OnCheckedChangeListener;
    import android.widget.TextView;
    
    
    public class panduanset extends Activity {
        private TextView panduannumber;
        private RadioGroup panduanRG;
        private int i,g;
        private Button panduanxunlian;
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_panduan_set);
            panduannumber=(TextView)findViewById(R.id.panduannumber);
            panduanRG=(RadioGroup)findViewById(R.id.panduangroup);
            panduanxunlian=(Button)findViewById(R.id.panduanxunlian);
            panduanRG.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                
                @Override
                public void onCheckedChanged(RadioGroup arg0, int arg1) {
                    // TODO Auto-generated method stub
                    i=arg1;
                }
            });
            panduanxunlian.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    g=Integer.valueOf(panduannumber.getText().toString());
                    Intent intent=new Intent();
                    Bundle bundle=new Bundle();
                    bundle.putInt("panduansuanfa", i);
                    bundle.putInt("panduanshumu",g);
                    intent.setClass(panduanset.this,panduanActivity.class);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            });
        }
    
        @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;
        }
    
    }

    panduanAcivity.java

    import java.util.Random;
    
    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.RadioButton;
    import android.widget.RadioGroup;
    import android.widget.Toast;
    import android.widget.RadioGroup.OnCheckedChangeListener;
    import android.widget.TextView;
    
    public class panduanActivity extends Activity{
        private Button next1;
        private Button result1;
        private RadioGroup panduan;
        private TextView timu1;
        private int index,i;
        private int k,j,l,sum,wrong,right,sign,label=0;
        private char a;
        private final Random num1=new Random();
        private final Random num2=new Random();
        private final Random r = new Random();
        private char[] ch = {'+','-','*','/'};
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_panduan);
            panduan=(RadioGroup)findViewById(R.id.group2);
            next1=(Button)findViewById(R.id.next1);
            result1=(Button)findViewById(R.id.result1);
            timu1=(TextView)findViewById(R.id.timu1);
            Bundle bundle=getIntent().getExtras();
            index=bundle.getInt("panduansuanfa");
            a=ch[index];
            i=bundle.getInt("panduanshumu");
             final String []answer=new String[i];
            String c=String.valueOf(num1.nextInt(100));
            String b=String.valueOf(num2.nextInt(100));
            String g=String.valueOf(r.nextInt(3));
            k=Integer.valueOf(g);
            l=Integer.valueOf(c);
            j=Integer.valueOf(b);
            String d=String.valueOf(a);    
            switch(index){
            case 0:
                sum=l+j;
                break;
            case 1:
                sum=l-j;
                break;
            case 2:
                sum=l*j;
                break;
            case 4:
                sum=l/j;
                break;
            }
            switch(k){
            case 0:
                timu1.setText(c+d+b+"="+String.valueOf(sum));
                right=0;
                break;
            case 1:
                timu1.setText(c+d+b+"="+String.valueOf(sum+1));
                right=1;
                break;
            case 2:
                timu1.setText(c+d+b+"="+String.valueOf(sum+2));
                right=1;
                break;
                default:
                    break;
            }
            panduan.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                
                @Override
                public void onCheckedChanged(RadioGroup arg0, int arg1) {
                    // TODO Auto-generated method stub
                    sign=arg1;
                    System.out.print(sign);
                }
            });
            next1.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    if(i!=0){
                if(sign==right){
                    Toast.makeText(panduanActivity.this, "选择正确", Toast.LENGTH_LONG).show();
                    answer[label]="right";
                }
                if(sign!=right){
                    Toast.makeText(panduanActivity.this, "选择错误", Toast.LENGTH_LONG).show();
                    answer[label]="wrong";
                }
                i--;
                label++;
                String c=String.valueOf(num1.nextInt(100));
                String b=String.valueOf(num2.nextInt(100));
                String g=String.valueOf(r.nextInt(3));
                k=Integer.valueOf(g);
                l=Integer.valueOf(c);
                j=Integer.valueOf(b);
                String d=String.valueOf(a);    
                switch(index){
                case 0:
                    sum=l+j;
                    break;
                case 1:
                    sum=l-j;
                    break;
                case 2:
                    sum=l*j;
                    break;
                case 4:
                    sum=l/j;
                    break;
                }
                switch(k){
                case 0:
                    timu1.setText(c+d+b+"="+String.valueOf(sum));
                    right=0;
                    break;
                case 1:
                    timu1.setText(c+d+b+"="+String.valueOf(sum+1));
                    right=1;
                    break;
                case 2:
                    timu1.setText(c+d+b+"="+String.valueOf(sum+2));
                    right=1;
                    break;
                    default:
                        break;
                }
                panduan.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                    
                    @Override
                    public void onCheckedChanged(RadioGroup arg0, int arg1) {
                        // TODO Auto-generated method stub
                        sign=arg1;
                        System.out.print(sign);
                    }
                });
                    }
                    else
                    {
                    Toast.makeText(panduanActivity.this,"题目已做完", Toast.LENGTH_LONG).show();
                    timu1.setText(null);
                    }
                }
            });
            result1.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                if(i!=0)
                    Toast.makeText(panduanActivity.this, "题目没有做完,请继续完成", Toast.LENGTH_LONG).show();
                else{
                    Intent intent=new Intent();
                    Bundle bundle2=new Bundle();
                    intent.setClass(panduanActivity.this,panduanresult.class);
                    bundle2.putInt("panduannumber", label);
                    bundle2.putStringArray("panduanarry", answer);
                    intent.putExtras(bundle2);
                    startActivity(intent);
                }
                    
                }
            });
        }
    
        @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;
        }
    
    
    }

    panduanresult.java

    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.TextView;
    
    public class panduanresult extends Activity{
        private TextView t1;
        private TextView t2;
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_panduan_result);
            t1=(TextView)findViewById(R.id.panduan12);
            t2=(TextView)findViewById(R.id.panduan13);
            Bundle bundle=getIntent().getExtras();
            int i=bundle.getInt("panduannumber");
            String []answer=bundle.getStringArray("panduanarry");
             String aa="";
             String aaa="";
            for(int g=0;g<i;g++){
                aa+=String.valueOf(g+1)+"
    ";
                aaa+=answer[g]+"
    ";
                t1.setText(aa);
                t2.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;
        }
    
    }

  • 相关阅读:
    block本质探寻五之atuto类型局部实例对象
    block本质探寻四之copy
    block本质探寻三之block类型
    Android Studio使用时遇见的一些问题+解决方法(持续更新)
    Android之练习MVVM+DataBinding框架模式
    解决 Mac Android Studio Gradle Sync 慢的问题
    Android之MVC、MVP、MVVM
    Android之同步与异步
    Android之Fragment
    Android之Fragment栈操作 commit()问题分析
  • 原文地址:https://www.cnblogs.com/babybluecsj/p/5034422.html
Copyright © 2011-2022 走看看