码迷,mamicode.com
首页 > 其他好文 > 详细

人品计算机

时间:2015-02-01 20:34:03      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:人品计算机

1,主界面

<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" >
    <TextView
        android:id="@+id/tv_name"
        android:textSize="20sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/name" />   
    <EditText
        android:id="@+id/et_name"
        android:layout_toRightOf="@+id/tv_name"
        android:layout_width="200dip"
        android:layout_height="wrap_content"
        android:hint="@string/hintName"/>  
    <Button
        android:id="@+id/btn_calc"
        android:layout_below="@+id/tv_name"
        android:background="#00ffff"
        android:layout_marginTop="30dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/calc"/>
    <TextView
        android:id="@+id/tv_show"
        android:layout_below="@+id/btn_calc"
        android:textColor="#ff0000"
        android:layout_marginTop="10dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/show"/>
</RelativeLayout>

2,功能的实现

package com.eduask.rpcalc;
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;
public class MainActivity extends Activity {
    private EditText et_name;
    private Button btn_calc;
    private TextView tv_show;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);  //加载布局的方法
        //找到相应的控件
        et_name = (EditText) findViewById(R.id.et_name);  //找到编辑姓名的控件
        btn_calc = (Button) findViewById(R.id.btn_calc);  //找到计算姓名的控件
        tv_show = (TextView) findViewById(R.id.tv_show);  //找到显示人品的控件      
        btn_calc.setOnClickListener(new OnClickListener() {         
            @Override
            public void onClick(View v) {
                String strName = et_name.getText().toString().trim();  //1,获取用户所输入姓名
                byte [] bytes = strName.getBytes();  //2,将得到的姓名转换称字节
                //遍历得到的字节,将其转换称十进制
                int count = 0;
                for (byte b : bytes) {  
                    int number = b % 0xff;
                    count += number;
                }
                count = Math.abs(count %100);  //取出每个值,让其小于100
                
                String rpText = getRPText(count);  //3,获取人品计算值
                tv_show.setText(strName+"您的人品值为:"+count+"\n"+rpText);  //4,显示人品结果
            }
        });
    }
    
/**
 * 人品计算值
 * @param rp
 * @return
 */
    private String getRPText(int rp) {
        String rpText = null;
        if (rp == 0) {
            rpText = "你一定不是人吧?怎么一点人品都没有?!";
        } else if (rp > 0 && rp <= 5) {
            rpText = "算了,跟你没什么人品好谈的...";
        } else if (rp > 5 && rp <= 10) {
            rpText = "是我不好...不应该跟你谈人品问题的...";
        } else if (rp > 10 && rp <= 15) {
            rpText = "杀过人没有?放过火没有?你应该无恶不做吧?";
        } else if (rp > 15 && rp <= 20) {
            rpText = "你貌似应该三岁就偷看隔壁大妈洗澡的吧...";
        } else if (rp > 20 && rp <= 25) {
            rpText = "你的人品之低下实在让人惊讶啊...";
        } else if (rp > 25 && rp <= 30) {
            rpText = "你的人品太差了。你应该有干坏事的嗜好吧?";
        } else if (rp > 30 && rp <= 35) {
            rpText = "你的人品真差!肯定经常做偷鸡摸狗的事...";
        } else if (rp > 35 && rp <= 40) {
            rpText = "你拥有如此差的人品请经常祈求佛祖保佑你吧...";
        } else if (rp > 40 && rp <= 45) {
            rpText = "老实交待..那些论坛上面经常出现的偷拍照是不是你的杰作?";
        } else if (rp > 45 && rp <= 50) {
            rpText = "你随地大小便之类的事没少干吧?";
        } else if (rp > 50 && rp <= 55) {
            rpText = "你的人品太差了..稍不小心就会去干坏事了吧?";
        } else if (rp > 55 && rp <= 60) {
            rpText = "你的人品很差了..要时刻克制住做坏事的冲动哦..";
        } else if (rp > 60 && rp <= 65) {
            rpText = "你的人品比较差了..要好好的约束自己啊..";
        } else if (rp > 65 && rp <= 70) {
            rpText = "你的人品勉勉强强..要自己好自为之..";
        } else if (rp > 70 && rp <= 75) {
            rpText = "有你这样的人品算是不错了..";
        } else if (rp > 75 && rp <= 80) {
            rpText = "你有较好的人品..继续保持..";
        } else if (rp > 80 && rp <= 85) {
            rpText = "你的人品不错..应该一表人才吧?";
        } else if (rp > 85 && rp <= 90) {
            rpText = "你的人品真好..做好事应该是你的爱好吧..";
        } else if (rp > 90 && rp <= 95) {
            rpText = "你的人品太好了..你就是当代活雷锋啊...";
        } else if (rp > 95 && rp <= 99) {
            rpText = "你是世人的榜样!";
        } else if (rp == 100) {
            rpText = "天啦!你不是人!你是神!!!";
        } else {
            rpText = "你的人品竟然负溢出了...我对你无语..";
        }
        return rpText;
    }
    @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;
    }
    
}


本文出自 “InProvence” 博客,谢绝转载!

人品计算机

标签:人品计算机

原文地址:http://9882931.blog.51cto.com/9872931/1610462

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!