07081方明星 实验5.docx

上传人:b****6 文档编号:7577278 上传时间:2023-01-25 格式:DOCX 页数:12 大小:55.43KB
下载 相关 举报
07081方明星 实验5.docx_第1页
第1页 / 共12页
07081方明星 实验5.docx_第2页
第2页 / 共12页
07081方明星 实验5.docx_第3页
第3页 / 共12页
07081方明星 实验5.docx_第4页
第4页 / 共12页
07081方明星 实验5.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

07081方明星 实验5.docx

《07081方明星 实验5.docx》由会员分享,可在线阅读,更多相关《07081方明星 实验5.docx(12页珍藏版)》请在冰豆网上搜索。

07081方明星 实验5.docx

07081方明星实验5

实验名称:

实验五根据身高计算标准体重

学号:

070812001姓名:

方明星

一、实验要求

根据身高计算标准体重

2、实验内容

1实验代码

Main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

layout_width="fill_parent"

android:

layout_height="fill_parent"

android:

background="@drawable/b3"

android:

orientation="vertical">

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

layout_gravity="center_horizontal"

android:

padding="20px"

android:

textSize="36dp"

android:

textColor="#60f"

android:

text="?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

!

"/>

android:

id="@+id/linearLayout1"

android:

gravity="center_vertical"

android:

layout_width="match_parent"

android:

layout_height="wrap_content">

android:

id="@+id/textView1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

textColor="#f000"

android:

textSize="28dp"

android:

text="?

?

:

"/>

android:

id="@+id/sex"

android:

orientation="horizontal"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content">

android:

id="@+id/radio0"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

checked="true"

android:

textSize="24dp"

android:

textColor="#f000"

android:

text="?

"/>

android:

id="@+id/radio1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

textColor="#f000"

android:

textSize="24dp"

android:

text="?

"/>

android:

id="@+id/linearLayout1"

android:

gravity="center_vertical"

android:

layout_width="match_parent"

android:

layout_height="wrap_content">

android:

id="@+id/textView1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

textSize="28dp"

android:

textColor="#f000"

android:

text="?

?

:

"/>

android:

id="@+id/stature"

android:

minWidth="100px"

android:

textSize="24dp"

android:

textColor="#000"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content">

android:

id="@+id/textView2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

textSize="20dp"

android:

textColor="#f000"

android:

text="cm"/>

android:

id="@+id/button1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

textColor="#ff0f"

android:

background="#0f6"

android:

textSize="24dp"

android:

text="@string/qudung"/>

Resure.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

layout_width="match_parent"

android:

layout_height="match_parent"

android:

background="@drawable/b3"

android:

orientation="vertical">

android:

id="@+id/sex"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

padding="10px"

android:

textSize="28dp"

android:

textColor="#f000"

android:

text="?

?

"/>

android:

id="@+id/stature"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

textColor="#f000"

android:

textSize="28dp"

android:

padding="10px"

android:

text="?

?

"/>

android:

id="@+id/weight"

android:

padding="10px"

android:

textSize="28dp"

android:

textColor="#f000"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="?

?

?

?

"/>

android:

id="@+id/button1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

textSize="24dp"

android:

background="#0f6"

android:

text="?

?

"/>

MainActivity

packagecom.mingrisoft;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.EditText;

importandroid.widget.RadioButton;

importandroid.widget.RadioGroup;

importandroid.widget.Toast;

publicclassMainActivityextendsActivity{

/**Calledwhentheactivityisfirstcreated.*/

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Buttonbutton=(Button)findViewById(R.id.button1);

button.setOnClickListener(newOnClickListener(){

@Override

publicvoidonClick(Viewv){

Infoinfo=newInfo();//实例化一个保存输入基本信息的对象

if("".equals(((EditText)findViewById(R.id.stature)).getText().toString())){

Toast.makeText(MainActivity.this,"请输入您的身高,否则不能计算!

",Toast.LENGTH_SHORT).show();

return;

}

intstature=Integer.parseInt(((EditText)findViewById(R.id.stature)).getText().toString());

RadioGroupsex=(RadioGroup)findViewById(R.id.sex);//获取设置性别的单选按钮组

//获取单选按钮组的值

for(inti=0;i

RadioButtonr=(RadioButton)sex.getChildAt(i);//根据索引值获取单选按钮

if(r.isChecked()){//判断单选按钮是否被选中

info.setSex(r.getText().toString());//获取被选中的单选按钮的值

break;//跳出for循环

}

}

info.setStature(stature);//设置身高

Bundlebundle=newBundle();//实例化一个Bundle对象

bundle.putSerializable("info",info);//将输入的基本信息保存到Bundle对象中

Intentintent=newIntent(MainActivity.this,ResultActivity.class);

intent.putExtras(bundle);//将bundle保存到Intent对象中

startActivity(intent);//启动intent对应的Activity

}

});

}

}

ResureActivity

packagecom.mingrisoft;

importjava.text.DecimalFormat;

importjava.text.NumberFormat;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.TextView;

publicclassResultActivityextendsActivity{

@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.result);//设置该Activity使用的布局

TextViewsex=(TextView)findViewById(R.id.sex);//获取显示性别的文本框

TextViewstature=(TextView)findViewById(R.id.stature);//获取显示身高的文本框

TextViewweight=(TextView)findViewById(R.id.weight);//获取显示标准体重的文本框

Intentintent=getIntent();//获取Intent对象

Bundlebundle=intent.getExtras();//获取传递的数据包

Infoinfo=(Info)bundle.getSerializable("info");//获取一个可序列化的info对象

sex.setText("您是一位"+info.getSex()+"士");//获取性别并显示到相应文本框中

stature.setText("您的身高是"+info.getStature()+"厘米");//获取身高并显示到相应文本框中

weight.setText("您的标准体重是"+getWeight(info.getSex(),info.getStature())+"公斤");//显示计算后的标准体重

Buttonbutton=(Button)findViewById(R.id.button1);

button.setOnClickListener(newOnClickListener(){

publicvoidonClick(Viewv){

finish();

}

});

}

/**

*功能:

计算标准体重

*@paramsex

*@paramstature

*@return

*/

privateStringgetWeight(Stringsex,floatstature){

Stringweight="";//保存体重

NumberFormatformat=newDecimalFormat();

if(sex.equals("男")){//计算男士标准体重

weight=format.format((stature-80)*0.7);

}else{//计算女士标准体重

weight=format.format((stature-70)*0.6);

}

returnweight;

}

}

Info.java

packagecom.mingrisoft;

importjava.io.Serializable;

publicclassInfoimplementsSerializable{

privatestaticfinallongserialVersionUID=1L;

privateStringsex="";//?

?

privateintstature=0;//?

?

publicStringgetSex(){

returnsex;

}

publicvoidsetSex(Stringsex){

this.sex=sex;

}

publicintgetStature(){

returnstature;

}

publicvoidsetStature(intstature){

this.stature=stature;

}

}

AndroidManifest.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

package="com.mingrisoft"

android:

versionCode="1"

android:

versionName="1.0">

minSdkVersion="15"/>

android:

icon="@drawable/c4"

android:

label="?

?

?

">

android:

label="?

?

?

?

"

android:

name=".MainActivity">

name="android.intent.action.MAIN"/>

name="android.intent.category.LAUNCHER"/>

android:

label="?

?

?

?

"

android:

icon="@drawable/ic_launcher"

android:

name=".ResultActivity">

三、实验结果

实验结果图

四、教师评价

 

指导教师签名:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 临床医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1