package com.itheima74.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText et_name;
private RadioGroup rg_group;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_name = (EditText) findViewById(R.id.et_name);
rg_group = (RadioGroup) findViewById(R.id.rg_group);
findViewById(R.id.bt_calculator).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = et_name.getText().toString().trim();
if (TextUtils.isEmpty(name)) {
Toast.makeText(MainActivity.this, "亲,请输入姓名", Toast.LENGTH_SHORT).show();
return;
}
int sex = 0;
int checkedRadioButtonId = rg_group.getCheckedRadioButtonId();
switch (checkedRadioButtonId) {
case R.id.rb_male:
sex = 1;
break;
case R.id.rb_female:
sex = 2;
break;
case R.id.rb_renyao:
sex = 3;
break;
}
if (sex == 0) {
Toast.makeText(MainActivity.this, "亲,请选择性别", Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent(getApplicationContext(), ResultActivity.class);
intent.putExtra("name", name);
intent.putExtra("sex", sex);
startActivity(intent);
}
});
}
}
package com.itheima74.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
/**
* Created by My on 2017/2/12.
*/
public class ResultActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
TextView tv_name = (TextView) findViewById(R.id.tv_name);
TextView tv_sex = (TextView) findViewById(R.id.tv_sex);
TextView tv_result = (TextView) findViewById(R.id.tv_result);
Intent intent = getIntent();
String name = intent.getStringExtra("name");
int sex = intent.getIntExtra("sex", 0);
tv_name.setText(name);
byte[] bytes = null;
try {
switch (sex) {
case 1:
tv_sex.setText("男");
bytes = name.getBytes("utf-8");
break;
case 2:
tv_sex.setText("女");
bytes = name.getBytes("GBK");
break;
case 3:
tv_sex.setText("人妖");
bytes = name.getBytes("iso_8859-1");
break;
}
} catch (Exception e) {
e.printStackTrace();
}
int total = 0;
int score;
for (byte b : bytes) {
total += b & 0xff;
}
score = Math.abs(total) % 100;
if (score == 0) {
tv_result.setText("得分:" + score + ",你一定不是人吧?怎么一点人品都没有?!");
} else if (score <= 5) {
tv_result.setText("得分:" + score + ",算了,跟你没什么人品好谈的...");
} else if (score <= 10) {
tv_result.setText("得分:" + score + ",是我不好...不应该跟你谈人品问题的...");
} else if (score <= 15) {
tv_result.setText("得分:" + score + ",杀过人没有?放过火没有?你应该无恶不做吧?");
} else if (score <= 20) {
tv_result.setText("得分:" + score + ",你貌似应该三岁就偷看隔壁大妈洗澡的吧...");
} else if (score <= 30) {
tv_result.setText("得分:" + score + ",你的人品太差了。你应该有干坏事的嗜好吧");
} else if (score <= 35) {
tv_result.setText("得分:" + score + ",你的人品真差!肯定经常做偷鸡摸狗的事...");
} else if (score <= 40) {
tv_result.setText("得分:" + score + ",你拥有如此差的人品请经常祈求佛祖保佑你吧...");
} else if (score <= 45) {
tv_result.setText("得分:" + score + ",老实交待..那些论坛上面经常出现的偷拍照是不是你的杰作?");
} else if (score <= 50) {
tv_result.setText("得分:" + score + ",你随地大小便之类的事没少干吧?");
} else if (score <= 55) {
tv_result.setText("得分:" + score + ",你的人品太差了..稍不小心就会去干坏事了吧?");
} else if (score <= 60) {
tv_result.setText("得分:" + score + ",你的人品很差了..要时刻克制住做坏事的冲动哦..");
} else if (score <= 65) {
tv_result.setText("得分:" + score + ",你的人品比较差了..要好好的约束自己啊..");
} else if (score <= 70) {
tv_result.setText("得分:" + score + ",你的人品勉勉强强..要自己好自为之..");
} else if (score <= 75) {
tv_result.setText("得分:" + score + ",有你这样的人品算是不错了..");
} else if (score <= 80) {
tv_result.setText("得分:" + score + ",你有较好的人品..继续保持..");
} else if (score <= 85) {
tv_result.setText("得分:" + score + ",你的人品不错..应该一表人才吧?");
} else if (score <= 90) {
tv_result.setText("得分:" + score + ",你的人品真好..做好事应该是你的爱好吧..");
} else if (score <= 95) {
tv_result.setText("得分:" + score + ",你的人品太好了..你就是当代活雷锋啊...");
} else if (score <= 100) {
tv_result.setText("得分:" + score + ",天啦!你不是人!你是神!!!");
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/37268.html