zoukankan      html  css  js  c++  java
  • 四则运算--第二次冲刺

    我们团队正在完善程序功能、有些算法正在研究当中,竭尽全力的去完成,再给我们点时间应该可以完成

    安卓Activity:

    package com.example.count_number;


    import android.os.Bundle;
    import android.app.Activity;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;



    public class MainActivity extends Activity {
        
        private int x,y;//用以产生x,y
        private int fhao;//用以产生符号
        
        private EditText t1,t2,t3;
        private Button b1;
        private int answer,sure;
        private EditText e1,e2;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            x = (int)(Math.random() *9)+1; //不能出现0
            y = (int)(Math.random() *9)+1; 
            fhao= (int)(Math.random() *4)+1; 
            t1=(EditText)findViewById(R.id.et1);
            t2=(EditText)findViewById(R.id.et2);
            t3=(EditText)findViewById(R.id.et3);
            b1=(Button)findViewById(R.id.button1);
            e1=(EditText)findViewById(R.id.editText1);
            e2=(EditText)findViewById(R.id.editText2);
            //显示
            t1.setText(x);
            switch(fhao)
            {
            case 1:
                t2.setText("+");
                sure=x+y;
                break;
            case 2:
                t2.setText("-");
                sure=x-y;
                break;
            case 3:
                t2.setText("*");
                sure=x*y;
                break;
            case 4:
                t2.setText("/");
                sure=x/y;
                break;        
            }
            t3.setText(y);
            
            //输入和确定答案
            b1.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    answer=Integer.parseInt(e1.getText().toString());
                    if(answer==sure)
                    {
                        e2.setText("正确");
                    }
                    if(answer!=sure)
                    {
                        e2.setText("错误");
                    }
                }
            });
            
        }

    }
    安卓XML 文件

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >

        <EditText
            android:id="@+id/et4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="23dp" />

        <EditText
            android:id="@+id/et1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText1"
            android:layout_alignParentTop="true" />

        <EditText
            android:id="@+id/et2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/textView1"
            android:layout_alignBottom="@+id/textView1"
            android:layout_alignRight="@+id/textView4"/>

        <EditText
            android:id="@+id/et3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/textView1"
            android:layout_alignBottom="@+id/textView1"
            android:layout_marginLeft="16dp"
            android:layout_toRightOf="@+id/editText1" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="145dp"
            android:ems="10" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/editText1"
            android:layout_alignLeft="@+id/editText1"
            android:layout_marginBottom="75dp"
            android:text="你的输入:" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="21dp"
            android:layout_toLeftOf="@+id/textView2"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/textView4"
            android:layout_alignLeft="@+id/editText2"
            android:layout_marginBottom="15dp"
            android:text="是否正确:" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/textView5"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="32dp"
            android:text="提交答案" />

    </RelativeLayout>

  • 相关阅读:
    杂记 后台代码取DataSource中的值,和不间断滚动JS
    利用IHttpModule实现URL地址转发功能
    在ASP.NET中跟踪和恢复大文件下载
    小记,取GB2312汉字的首字母
    小记,提供文件下载,并控制下载速度
    黑客知识系列之木马程序隐身的技术
    经典算法C#四种排序算法
    跟我学做c#皮肤美化(六)
    【转】xPath语法介绍
    一个httpwebrequest异步下载的例子
  • 原文地址:https://www.cnblogs.com/hwj23/p/5009730.html
Copyright © 2011-2022 走看看