小学四则运算APP 第二阶段冲刺-第三天

时间:2021-12-09 23:52:07

团队成员:陈淑筠、杨家安、陈曦

团队选题:小学四则运算APP

第二次冲刺阶段时间:11.29~12.09

本次发布的是判断题的部分代码

panduanset.java

import com.example.calculator.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView; public class panduanset extends Activity {
private TextView panduannumber;
private RadioGroup panduanRG;
private int i,g;
private Button panduanxunlian;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_panduan_set);
panduannumber=(TextView)findViewById(R.id.panduannumber);
panduanRG=(RadioGroup)findViewById(R.id.panduangroup);
panduanxunlian=(Button)findViewById(R.id.panduanxunlian);
panduanRG.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
i=arg1;
}
});
panduanxunlian.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
g=Integer.valueOf(panduannumber.getText().toString());
Intent intent=new Intent();
Bundle bundle=new Bundle();
bundle.putInt("panduansuanfa", i);
bundle.putInt("panduanshumu",g);
intent.setClass(panduanset.this,panduanActivity.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }

pandaunactivtity.java

import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView; public class panduanActivity extends Activity{
private Button next1;
private Button result1;
private TextView timu1;
private int index,i;
private int k,j,l,sum;
private char a;
private final Random num1=new Random();
private final Random num2=new Random();
private final Random r = new Random();
private char[] ch = {'+','-','*','/'};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_panduan);
Bundle bundle=getIntent().getExtras();
index=bundle.getInt("panduansuanfa");
a=ch[index];
i=bundle.getInt("panduanshumu");
String c=String.valueOf(num1.nextInt());
String b=String.valueOf(num2.nextInt());
String g=String.valueOf(r.nextInt());
k=Integer.valueOf(g);
l=Integer.valueOf(c);
j=Integer.valueOf(b);
String d=String.valueOf(a);
switch(index){
case :
sum=l+j;
break;
case :
sum=l-j;
break;
case :
sum=l*j;
break;
case :
sum=l/j;
break;
}
switch(k){
case :
timu1.setText(c+d+b+"="+String.valueOf(sum));
break;
case :
timu1.setText(c+d+b+"="+String.valueOf(sum+));
break;
case :
timu1.setText(c+d+b+"="+String.valueOf(sum+));
default:
break;
}
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }