Java和安卓实习报告

项目(设计)题目:

      健康助手——最佳情侣身高测试


目录

第一章 项目背景及意义................................................................................................... 2

第二章 基本知识.............................................................................................................. 3

2.1 基本知识............................................................................................................ 3

2.1.1 JAVA基础................................................................................................. 3

2.1.2 android基础........................................................................................... 4

第三章 项目详细设计....................................................................................................... 5

3.1 需求概述............................................................................................................ 5

3.2 项目的功能........................................................................................................ 6

3.3 运行及开发环境................................................................................................. 6

3.4模块详细设计及关键代码.................................................................................... 6

3.4.1 主界面设计.............................................................................................. 6

3.4.2 xml代码.................................................................................................. 6

3.4.3 后台代码................................................................................................ 10

3.4.4 应用实现................................................................................................ 14

第四章 项目总结............................................................................................................ 14

4.1 实训收获.......................................................................................................... 14

4.2 未来规划.......................................................................................................... 15

第一章 项目背景及意义

在紧张的2周java及android实训后,作为一个结业的项目,由于时间原因,疏漏之处在所难免。因为这是第一次接触和学习java语言和Android,所以一些比较复杂的项目我们是写不了的,所以就想写一个简单的健康小助手。

刚开始,在实习一个星期后,我们进行了分组。小组成员确定下来后,在讨论做什么的时候,我们想了很多,但由于我们都是刚刚接触Java和Android,所以就想着选一个在我们这些初学者能力范围之内的项目。经过一段时间的讨论,我们打算写一个健康小助手,让它包含计算器、体重计、最佳情侣身高匹配等小应用。最后再经过一段时间的反复思考以及反复的方案设计和选定后,才确定下来。

这样一个健康的小插件,在人们的生活中也可以给人们带来很多方便。比如计算器可以在人们需要计算大量数据的时候,可以为他们提供便利;体重计可以为你的身体健康提供帮助,可以帮你检测身体,如果你需要减肥,它将是你最好的伙伴;而最佳情侣身高匹配这一应用可以为你推荐你人生中另一半的身高,并评论你最佳情侣的身高和你心目中的最佳情侣身高的差距和你的幸福指数。而我做的就是最佳情侣匹配这个小应用,主要帮助人们找到最适合自己的情侣的身高。

第二章 基本知识

2.1 基本知识

2.1.1 JAVA基础

Jdk开发工具的安装以及使用:到oracle官网下载windows安装包进行安装,然后进行环境变量配置,新建

JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_71,

CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;

在path添加

%JAVA_HOME%\bin;

Java常见关键字:class类,interface接口,public公共权限,private私有权限,protected受保护权限,extends继承,abstract抽象等。

Java数据类型:逻辑型boolean,字符型char,整数型byte,short,int,

Long;浮点型:float,double。

Java运算符:算术运算符:  +,-,*,/,%,++,--;关系运算符: >,<,>=,<=,= =,!=;逻辑运算符: !,&&,||;位运算符: &,|,^,~ , >>,<<,>>>;赋值运算符:  =;扩展赋值运算符:+=,- =,* =,/ =;字符串连接运算符:+ 。三目条件运算符,语法格式:x ? y : z。

Java语句:条件语句 - 根据不同条件,执行不同语句。if 、if .. Else、if .. else if、if .. else if .. else if .. Else、switch;循环语句 – 重复执行某些动作:for、for..each(JDK1.5语法)、while、do .. While。

Java面向对象:面向对象是针对面向过程的,传统的结构化程序设计通过一系列的过程(即算法)来求解问题,接着寻找存储数据的方式。即算法是第一位的,而数据结构是第二位的。OOP却调换了这个次序,将数据放在第一位,然后再考虑操纵数据的算法。

Java类、对象、特征:类的概念,类的构成(属性、方法);对象的概念,初始化方法,方法的重载,this关键字;封装,继承(重写,super关键字,构造方法之继承),多态。

Java抽象类,接口,内部类,匿名内部类:抽象类:当编写一个类时,我们往往会为该类定义一些方法,这些方法是用来描述该类的行为方式,那么这些方法都有具体的方法体。接口:抽象类是从多个类中抽象出来的模板,若要将这种抽象进行得更彻底,就得用到一种特殊的“抽象类”;在一个类的内部定义的类就称为内部类,内部类可以处于4种访问级别(public、protected、默认和private);匿名内部类必须继承一个父类或者实现一个接口,但最多只能是一个父类或实现一个接口。

2.1.2 android基础

Android体系结构:Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。另外android应用的范围不仅仅在手机,还被应用在汽车、平板电脑、和智能上网设备上、机顶盒以及智能穿戴设备。

Android开发环境:下载安装JDK 和Eclipse。

Android常见控件:TextView、EditText、ImageView、Button、ImageButton、RadioButton、CheckBox、ProgressBar、RatingBar、Spinner、Dialog。

Android资源类型:src/  java原代码存放目录;gen/ 自动生成目录;assets资源目录;bin目录;libs目录;res/ 资源(Resource)目录;AndroidManifest.xml 项目清单文件;default.properties;res/ 资源(Resource)目录;layout:存放布局xml文件;menu:存放菜单定义的xml文件。

Android界面设计:Activity的创建与配置方式、Android界面跳转、Android界面间传值、Application用法、回调机制、Android生命周期、Android加载模式、Intent用法。

第三章 项目详细设计

3.1 需求概述

情侣间的身高差距影响着牵手、拥抱、接吻等等,对双方的感情培养有着关键的作用。那么多少的身高差才是最适合的呢?这就需要我们开发一个关于情侣之间最佳情侣身高的小应用,帮助人们找到最适合自己的情侣的身高。

3.2 项目的功能

    给你推荐适合你的最理想女朋友的身高,同时与你心目中的女生身高进行对比,并且对此进行评价,让你能更好的选择适合你的女友身高。

3.3 运行及开发环境

运行环境:Android,开发环境: JDK 和Eclipse

3.4模块详细设计及关键代码

3.4.1 主界面设计

3.4.2 xml代码

activity_lovers.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="com.example.zuijiaqinglv.MainActivity$PlaceholderFragment" >

   <TextView android:id="@+id/res_content"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:textSize="18sp"

       android:textColor="#12f"

       />

   

    <TextView android:id="@+id/res_not"

       android:layout_width="wrap_content"

        android:layout_below="@id/res_content"

       android:layout_height="wrap_content"

       android:layout_centerInParent="true"

       android:textSize="14sp"

       android:textColor="#f12"

       android:text="您好!请填写您的信息:"

       />

    <EditText

        android:id="@+id/editText1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignBaseline="@+id/textView1"

        android:layout_alignBottom="@+id/textView1"

        android:layout_alignLeft="@+id/res_not"

        android:layout_marginLeft="49dp"

        android:ems="10"

        android:inputType="number"

        android:hint="输入您的身高/cm">

        <requestFocus />

    </EditText>

   <RadioGroup

       android:id="@+id/res_gender"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignTop="@+id/textView2"

               android:layout_centerHorizontal="true"

        >

        <RadioButton

               android:id="@+id/res_rb_man"

               android:layout_width="wrap_content"

               android:layout_height="wrap_content"

               android:checked="true"

               android:text="男" />

      

           <RadioButton

               android:id="@+id/res_rb_woman"

               android:layout_width="wrap_content"

               android:layout_height="wrap_content"

               android:text="女" />

       </RadioGroup>

   

    <TextView

        android:id="@+id/textView2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView1"

        android:layout_below="@+id/editText1"

        android:layout_marginTop="19dp"

        android:text="性别:" />

    <EditText

        android:id="@+id/EditText02"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/res_content"

        android:layout_alignRight="@+id/editText1"

        android:layout_below="@+id/TextView01"

        android:ems="10"

        android:hint="输入您心中最佳情侣的身高/cm"

        android:inputType="number" />

    <TextView

        android:id="@+id/TextView01"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView2"

        android:layout_below="@+id/res_gender"

        android:text="您理想中最佳情侣的身高:" />

    <TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_below="@+id/res_not"

        android:layout_marginTop="30dp"

        android:text="您的身高:" />

    <Button

        android:id="@+id/buttonn"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_below="@+id/EditText02"

        android:layout_marginTop="44dp"

        android:paddingLeft="80dp"

        android:paddingRight="80dp"

        android:layout_centerHorizontal="true"

        android:text="检测" />

</RelativeLayout>

activity_show.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="com.yangji.login.MainActivity$PlaceholderFragment" >

    <TextView android:id="@+id/main_text"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_centerInParent="true"

        android:textSize="20sp"

        android:textColor="#f12"/>

    <Button

        android:id="@+id/button1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"

        android:layout_alignRight="@+id/main_text"

        android:layout_marginBottom="19dp"

        android:layout_marginRight="66dp"

        android:onClick="exit"

        android:text="返回" />

   

</RelativeLayout>

3.4.3 后台代码

LoversActivity.java:

package com.example.job;

import android.content.Intent;

import android.os.Bundle;

import android.support.v7.app.ActionBarActivity;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.Toast;

public class LoversActivity extends ActionBarActivity implements

              OnClickListener {

       private EditText heightEt;

       private RadioGroup genderRg;

       private RadioButton maleRb;

       private RadioButton femaleRb;

       private EditText holeHeightEt;

       private Button checkBtn;

       @Override

       protected void onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);

              setContentView(R.layout.activity_lovers); // 设置显示视图

              // 找到界面各组件

              heightEt = (EditText) findViewById(R.id.editText1);

              genderRg = (RadioGroup) findViewById(R.id.res_gender);

              maleRb = (RadioButton) findViewById(R.id.res_rb_man);

              femaleRb = (RadioButton) findViewById(R.id.res_rb_woman);

              holeHeightEt = (EditText) findViewById(R.id.EditText02);

              checkBtn = (Button) findViewById(R.id.buttonn);

              checkBtn.setOnClickListener(this);

       }

       // 处理组件点击事件

       @Override

       public void onClick(View view) {

              switch (view.getId()) {

              case R.id.buttonn:

                     checkHeight();

                     break;

              }

       }

       // 检测并评论身高

       private void checkHeight() {

              if (heightEt.getText().toString().length() == 0) {

                     Toast.makeText(this, "您的身高不能为空", Toast.LENGTH_LONG).show();

              } else if (holeHeightEt.getText().toString().length() == 0) {

                     Toast.makeText(this, "最佳情侣身高不能为空", Toast.LENGTH_LONG).show();

              } else {

                     int height = Integer.parseInt(heightEt.getText().toString());

                     int hopeHeight = Integer

                                   .parseInt(holeHeightEt.getText().toString());

                     float objHeight = 0f;

                     int resId = genderRg.getCheckedRadioButtonId();

                     if (resId == R.id.res_rb_man) {

                            // 男生

                            objHeight = (float) (height / 1.09);

                     } else if (resId == R.id.res_rb_woman) {

                            // 女生

                            objHeight = (float) (height * 1.09);

                     } else {

                            // 人妖

                            objHeight = (float) height;

                     }

                     String notice = "您的身高:【" + height + "】\n您期望对象的身高:【" + hopeHeight

                                   + "】\n推荐对象身高:【" + objHeight + "】\n评论:";

                     if ((objHeight - hopeHeight) > 15) {

                            notice += "靠!你们要逆天啊!";

                     }

                     else if (( hopeHeight-objHeight) > 15) {

                            notice += "靠!你们要逆天啊!";

                     }

                     else if ((objHeight - hopeHeight) > 10) {

                            notice += "你们差距太大,可远观不可亵玩焉!";

                     }

                     else if ((hopeHeight-objHeight) > 10) {

                            notice += "你们差距不大,但择偶请慎重!";

                     }

                     else if ((hopeHeight-objHeight) > 5) {

                            notice += "你们差距太大,可远观不可亵玩焉!";

                     }

                     else if ((objHeight-hopeHeight) > 5) {

                            notice += "你们差距太大,可远观不可亵玩焉!";

                     }

                     else {

                            notice += "你们真是郎才女貌,天生一对!";

                     }

                     Intent intent = new Intent(this, ShowActivity.class);

                     Bundle bundle = new Bundle();

                     bundle.putString("notice", notice);

                     intent.putExtras(bundle);

                     startActivity(intent);

              }

       }

}

ShowActivity.java:

package com.example.job;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.TextView;

public class ShowActivity extends Activity

{

       private TextView mainTx;

      

       @Override

       protected void onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);

              // 设置显示视图

              setContentView(R.layout.activity_show);

              // 找到界面中间的文字组件

              mainTx = (TextView) findViewById(R.id.main_text);

             

              // 获取上一个界面中传来的值

              Bundle bundle = getIntent().getExtras();

              // 为文字组件设置显示内容

              mainTx.setText(bundle.getString("notice"));

       }

      

       //返回前一个页面

       public void exit(View view){

              finish();

       }

}

3.4.4 应用实现

第四章 项目总结

4.1 实训收获

此次只实习了短短的两周。虽说时间很短,但其中的每一天都使我收获很大、受益匪浅,它不仅使我在理论上对Java有了全新的认识,在实践能力上也得到了提高,真正地做到了学以致用,更学到了很多做人的道理,对我来说受益非浅。除此以外,也让我知道了什么叫团队,怎样和团队分工合作;同时我还学会了如何更好地与别人沟通,如何更好地去陈述自己的观点,如何说服别人认同自己的观点。这也是第一次让我亲身感受到理论与实际的相结合,让我大开眼界。也是对以前所学知识的一个初审吧!这次实习对于我以后学习、找工作也是受益菲浅的,在短短的两周中相信这些宝贵的经验会成为我今后成功的重要的基石;这对于我的学业,乃至我以后人生的影响无疑是极其深远的。

这次实习虽然是我们的第一次,不过同学们表现不错,由此看来,我们在进入大学的这两年里学到了不少的专业知识,只是自己感觉不到而已。对于所学专业,我们不能过于自卑和担忧,否则会妨碍自己学习。实习是学习的重要环节,有利于我们巩固专业知识、掌握工作技能,提高就业筹码。

这次实习为我提供了与众不同的学习方法和学习体会,从书本中面对现实,为我将来走上社会打下了扎实的基础。作为在校信息与计算科学的学生,现在我能做的就是吸取知识,提高自身的综合素质,提高自己的职业技能,自己有了能力,到时候才会是“车到山前必有路”。我相信在不久的未来,会有属于我自己的一片天空。

4.2 未来规划

我希望自己在以后的学习或工作中以务实的态度给提供更多的机会锻炼自己,为自己的成才与就业奠定坚实的基础;并希望自己要做好角色定位,将自己所学的知识,学熟、学精。

多学习和收集与专业有关的资料,来提高自己的专业水平,同时多请教经验丰富的老师,使他们好的经验能够对自己起到借鉴作用,在他们的帮助下,能够很快的培养自己的专业技能及节省时间,避免做无用功,也可以让自己了解很多专业上的捷径,从而减少自己会遇到的挫折和错误

相关推荐