实验题目:

将小学四则运算整合成网页版或者是Android版。实现有无余数,减法有无负数。。。。

设计思路:

由于学到的基础知识不足,只能设计简单的加减乘除,界面设计简单,代码量少,只是达到了入门级的水平。

实验代码:

<LinearLayout 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"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity"
android:orientation="horizontal"> <EditText
android:id="@+id/num1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12px"
android:text="请输入第一个数字"/> <TextView
android:id="@+id/tips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""/> <EditText
android:id="@+id/num2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12px"
android:text="请输入第二个数字"/> <TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="/> <TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12px"
android:text="计算结果"/> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity"
android:orientation="horizontal"> <Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"/> <Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"/> <Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*"/> <Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"/> </LinearLayout> </LinearLayout> .java文件 public class MainActivity extends Activity {
private EditText num1=null;
private EditText num2=null;
private TextView result=null;
//表示的是符号
private TextView tips=null;
private Button butAdd=null;
private Button butSub=null;
private Button butMul=null;
private Button butDiv=null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.num1=(EditText)super.findViewById(R.id.num1);
this.num2=(EditText)super.findViewById(R.id.num2);
this.result=(TextView)super.findViewById(R.id.result);
this.tips=(TextView)super.findViewById(R.id.tips);
this.butAdd=(Button)super.findViewById(R.id.add);
this.butSub=(Button)super.findViewById(R.id.sub);
this.butMul=(Button)super.findViewById(R.id.mul);
this.butDiv=(Button)super.findViewById(R.id.div);
//增加监听
this.butAdd.setOnClickListener(new AddListener());
this.butSub.setOnClickListener(new SubListener());
this.butMul.setOnClickListener(new MulListener());
this.butDiv.setOnClickListener(new DivListener());
this.num1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
MainActivity.this.num1.setText("");
}
});
this.num2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
MainActivity.this.num2.setText("");
}
});
} //加法操作
public class AddListener implements OnClickListener{
int onenum=0;
int twonum=0;
public void onClick(View v) {
onenum=Integer.parseInt(MainActivity.this.num1.getText().toString());
twonum=Integer.parseInt(MainActivity.this.num2.getText().toString());
MainActivity.this.tips.setText("+");
MainActivity.this.result.setText((onenum+twonum)+"");
}
} //减法操作
public class SubListener implements OnClickListener{
int onenum=0;
int twonum=0;
public void onClick(View v) {
onenum=Integer.parseInt(MainActivity.this.num1.getText().toString());
twonum=Integer.parseInt(MainActivity.this.num2.getText().toString());
MainActivity.this.tips.setText("-");
MainActivity.this.result.setText((onenum-twonum)+"");
}
}
//乘法操作
public class MulListener implements OnClickListener{
int onenum=0;
int twonum=0;
public void onClick(View v) {
onenum=Integer.parseInt(MainActivity.this.num1.getText().toString());
twonum=Integer.parseInt(MainActivity.this.num2.getText().toString());
MainActivity.this.tips.setText("*");
MainActivity.this.result.setText((onenum*twonum)+"");
}
}
//除法操作
public class DivListener implements OnClickListener{
int onenum=0;
int twonum=0;
public void onClick(View v) {
onenum=Integer.parseInt(MainActivity.this.num1.getText().toString());
twonum=Integer.parseInt(MainActivity.this.num2.getText().toString());
MainActivity.this.tips.setText("/");
MainActivity.this.result.setText((onenum/twonum)+"");
}
}
}

实验截图:

实验总结:

由于缺少相关的知识,只能做到基础的功能,希望自己多学点Android知识。更上一层楼,不在这样写下去,很伤心的,别人都会啊!学会了基本BUTTON设置TEXTFILED设置。。。但是极其缺少的是对算法的了解,堆栈的操作。

队友博客地址:http://www.cnblogs.com/zjj123456/

四则运算(Android)版的更多相关文章

  1. 四则运算(Android)版

    实验题目: 将小学四则运算整合成网页版或者是Android版.实现有无余数,减法有无负数.... 设计思路: 由于学到的基础知识不足,只能设计简单的加减乘除,界面设计简单,代码量少,只是达到了入门级的 ...

  2. 四则运算APP版

    (一)四则运算APP版 这这个Demo的目的就是强化一下本周学习的Android的Jetpack里的新内容,接下来我将通过这个Demo来展示我所学到的新知识. 先列出新学到的知识:ViewModel, ...

  3. 【项目记录】-液化气配送app android版

    15年底参与过甲方呼叫中心平台开发.液化气配送app android版要求1个月开发完成.开发此项目以前我只有过一周android的开发经验.(与甲方签署过保密协议,遵循职业道德有些敏感信息不能写.) ...

  4. 还是俄罗斯方块之android版

    前面的,口水话 请直接跳过. 虽然现在不比以前了 也没多少人气了,放到首页 都不到几百的点击量.也许博客园整体水平也是在往水的方向发展.不谈那些了,哥也曾经辉煌过 有过一天上千的点击量 ,哥也曾经有过 ...

  5. android版高仿淘宝客户端源码V2.3

    android版高仿淘宝客户端源码V2.3,这个版本我已经更新到2.3了,源码也上传到源码天堂那里了,大家可以看一下吧,该应用实现了我们常用的购物功能了,也就是在手机上进行网购的流程的,如查看产品(浏 ...

  6. Android版的菜谱客户端应用源码完整版

    Android版的菜谱客户端应用源码完整版,这个文章是从安卓教程网转载过来的,不是本人的原创,希望能够帮到大家的学习吧. <ignore_js_op> 152936qc7jdnv6vo0c ...

  7. 结对编程项目——四则运算vs版

    结对编程项目--四则运算vs版 1)小伙伴信息:        学号:130201238 赵莹        博客地址:点我进入 小伙伴的博客 2)实现的功能: 实现带有用户界面的四则运算:将原只能在 ...

  8. Android版2048

    虽然说2048是好久前比较火的小游戏,但直到最近才有机会去研究下2048实现的源码,这里就简单写一下我(bie)的(ren)思路: 首先2048需要有十六个卡片,这个卡片可以用FrameLayout的 ...

  9. Android版-支付宝APP支付

    此项目已开源 赶快来围观 Start支持下吧 [客户端开源地址-JPay][服务端端开源地址-在com.javen.alipay 包名下] 上一篇详细介绍了微信APP支付 点击这里 此篇文章来详细介绍 ...

  10. Android版Ftp服务端软件

    分享一款开发的Android版Ftp服务端软件,支持Android4.0及以上版本,可以实现局域网无线传输文件到手机,或者把手机上的多媒体文件分享到iPad等设备来扩展这些设备的存储空间,详情请见软件 ...

随机推荐

  1. ubuntu 使用wine卸载软件

    现在的网络应用许多被windows绑架了,有时候不得不下载一些.exe的的东西在ubuntu下载配合一下,但是后来我想卸载这些.exe应用程序,于是百度了一下,一位博主写的好,如下,晒出来: cd ~ ...

  2. Fragment使用findFragmentById返回null

    @Override public void onClick(View v) { switch (v.getId()){ case R.id.btn1: replaceFragment(new Anot ...

  3. Nginx-ngx_lua模块原理和内置函数

    ngx_lua模块的原理: 1.每个worker(工作进程)创建一个Lua VM,worker内所有协程共享VM:2.将Nginx I/O原语封装后注入 Lua VM,允许Lua代码直接访问:3.每个 ...

  4. C语言 gets()和scanf()函数的区别

    scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别.若想从键盘上输入字符串"hi hello",则应该使用 gets 函数. gets可以接收空格:而sc ...

  5. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十三)之附加功能-自定义皮肤

    前言 本篇要讲的算是一个layim代码功能扩充.在原来的laim中已经有自带的换肤功能,而且在skin配置中,你可以添加自己想要的皮肤图片路径.这些内容在接下来都不会涉及,本篇要讲的是自定义皮肤功能, ...

  6. 基于MATLAB的GUI(Graphical User Interface)音频实时显示设计

    摘要:本文章的设计主要讲基于matlab的gui音频实时显示设计,此次设计的gui相当于一个简洁的音乐播放器,界面只有”录音“和”播放“两个控件,哈哈,够简洁吧.通过”录音“按钮可以实现声音从电脑的声 ...

  7. spring + spring mvc可能会遇到的问题

    Spring容器优先加载由ServletContextListener(对应applicationContext.xml)产生的父容器,而SpringMVC(对应mvc_dispatcher_serv ...

  8. java反射学习笔记

    1.java反射概念 JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功 ...

  9. 关于iscroll阻止浏览器默认动作

    使用iscroll时,移动端遇到需要长按复制功能,但是iscroll屏蔽了浏览器默认事件,所以实现不了. 解决方案: myScroll = new IScroll('#wrapper',{ preve ...

  10. Java集合---LinkedList源码解析

    一.源码解析1. LinkedList类定义2.LinkedList数据结构原理3.私有属性4.构造方法5.元素添加add()及原理6.删除数据remove()7.数据获取get()8.数据复制clo ...