admin 管理员组文章数量: 1184232
2023年12月18日发(作者:turnport)
《Android基础》课程设计
一、设计课题
基于Android的简易计算机的设计与实现
二、设计功能
系统具有以下功能:
加、减、乘、除、删除、清零
三、操作环境
1) Windows操作系统
2) JDK开发环境
3) eclipse ADT集成开发环境
四、设计场所
第1页
五、设计过程(设计内容及主要程序模块)
计算模块:
计算器界面,如图所示:
加、减、乘、除、删除和清零代码如下:
package ;
import qi.R;
import ;
import ty;
import ;
import ;
import ;
import kListener;
import ;
import xt;
第2页
public class MainActivity extends Activity implements OnClickListener{
private EditText etInput;
private Button btOne;
private Button btTwo;
private Button btThree;
private Button btFour;
private Button btFive;
private Button btSix;
private Button btSeven;
private Button btEight;
private Button btNine;
private Button btZero;
private Button btPoint;
private Button btJia;
private Button btJian;
private Button btMul;
private Button btDivide;
private Button btEqu;
private Button btClear;
private Button btDel;
boolean clear_flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
te(savedInstanceState);
setContentView(ty_main);
etInput=(EditText) findViewById(t);
btOne=(Button) findViewById();
btTwo=(Button) findViewById();
btThree=(Button) findViewById(e);
btFour=(Button) findViewById();
btFive=(Button) findViewById();
btSix=(Button) findViewById();
btSeven=(Button) findViewById(n);
btEight=(Button) findViewById(t);
btNine=(Button) findViewById();
btZero=(Button) findViewById();
btPoint=(Button) findViewById(t);
btJia=(Button) findViewById();
btJian=(Button) findViewById();
btMul=(Button) findViewById();
btDivide=(Button) findViewById(de);
btEqu=(Button) findViewById();
第3页
}
btClear=(Button) findViewById(r);
btDel=(Button) findViewById();
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
lickListener(this);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String etinput=t().toString();
switch(()){
case :
case :
case :
case e:
case :
case :
case :
case n:
case t:
case :
第4页
case t:
if(clear_flag){
clear_flag=false;
etinput="";
t("");
}
t(etinput+((Button)v).getText());
break;
case :
case :
case :
case de:
if(clear_flag){
clear_flag=false;
etinput="";
t("");
}
t(etinput+" "+((Button)v).getText()+" ");
break;
case :
if(clear_flag){
clear_flag=false;
etinput="";
t("");
}else if(etinput!=null&&!("")){
t(ing(0,()-1));
}
break;
case r:
clear_flag=false;
etinput="";
t("");
break;
case :
getResult();
break;
}
}
public void getResult(){
String exp=t().toString();
if(exp==null||("")){
return;
}
if(!ns(" ")){
return;
第5页
}
if(clear_flag){
clear_flag=false;
return;
}
clear_flag=true;
double result=0;
String s1=ing(0,f(" "));
String op=ing(f(" ")+1,f(" ")+2);
String s2=ing(f(" ")+3);
if(!("")&&!("")){
double d1=ouble(s1);
double d2=ouble(s2);
if(("+")){
result=d1+d2;
}else if(("-")){
result=d1-d2;
}else if(("*")){
result=d1*d2;
}else if(("/")){
if(d2==0){
result=0;
}else{
result=d1/d2;
}
}
if(!ns(".")&&!ns(".")&&!("/")){
int r=(int)result;
t(r+"");
}else{
t(result+"");
}
}else if(!("")&&("")){
t(exp);
}else if(("")&&!("")){
double d2=ouble(s2);
if(("+")){
result=0+d2;
}else if(("-")){
result=0-d2;
}else if(("*")){
result=0;
}else if(("/")){
result=0;
}
第6页
}
}
if(!ns(".")&&!ns(".")&&!("/")){
int r=(int)result;
t(r+"");
}else{
t(result+"");
}
}else{
t("");
}
六、本次设计中用到的课程知识点(列出主要知识点)
1) 控件Button,TextView
2) 界面布局GridLayout,LinearLayout,EditText
3) Activity 组件
七、设计中遇到的问题及解决方法
1. 在计算机中点击一个数字,无法计算。
必须要把字符串改为double类型
2. 输入完数字以后,点击”=”无法运行
必须要在字符前加上” ”(空格)
附件:
第7页
版权声明:本文标题:《Android基础》基于Android的简易计算机的设计与实现 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1702911551a435667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论