结对项目

Posted a19990808

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了结对项目相关的知识,希望对你有一定的参考价值。

18软工4班3118005096赖学程。18软工4班3118005098利国铭

需求:实现一个自动生成小学四则运算题目的命令行程序(也可以用图像界面,具有相似功能)。

分析:设置一个函数,自动生成,加减乘除,然后用,对话框形式让用户输入答案,最后用配对传输数据。

困难:写博客太难了。感觉不会再爱了。

过程:活动一:

public class MainActivity extends AppCompatActivity {
int a;
private SoundPool soundPool;//声明一个SoundPool
private int soundID;//创建某个声音对应的音频ID

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText myEditText=(EditText)findViewById(R.id.edittext);
Button myButton=(Button)findViewById(R.id.bottom);
initSound();//按钮加声音
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
a=Integer.parseInt(myEditText.getText().toString());
}catch (Exception e){
Toast.makeText(MainActivity.this,"请输入正确的数字",Toast.LENGTH_SHORT).show();
}
if(a==0)Toast.makeText(MainActivity.this,"输入0干啥",Toast.LENGTH_SHORT).show();
if(30<a)Toast.makeText(MainActivity.this,"输入那么大干啥",Toast.LENGTH_SHORT).show();
if(0<a&&a<31){
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
intent.putExtra("lai", a);
startActivity(intent);

}
}
});
}
@SuppressLint("NewApi")//按钮加声音
private void initSound() {
soundPool = new SoundPool.Builder().build();
soundID = soundPool.load(this,R.raw.li, 1);
}
private void playSound() {//按钮加声音
soundPool.play(
soundID,
0.1f, //左耳道音量【0~1】
0.5f, //右耳道音量【0~1】
0, //播放优先级【0表示最低优先级】
1, //循环模式【0表示循环一次,-1表示一直循环,其他表示数字+1表示当前数字对应的循环次数】
1 //播放速度【1是正常,范围从0~2】
);
}
第二个活动;
public class Main2Activity extends AppCompatActivity {
int a=0;
public List<String> ti=new ArrayList<String>();
int[] di;String wu="答案";String qi="答对的题有:";
String ai;int[] b;
String string;int dia;
private MediaPlayer mp;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.aoo, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.a:
att();
Intent intent2 = new Intent(Main2Activity.this,Main4Activity.class);
intent2.putExtra("aaa",wu);
startActivity(intent2);
break;
case R.id.b:
Intent intent = new Intent(Main2Activity.this,Main3Activity.class);
intent.putExtra("aaa",a);
startActivity(intent);
break;
case R.id.c:
stt();
Intent intent3 = new Intent(Main2Activity.this,Main5Activity.class);
intent3.putExtra("aaa",qi);
startActivity(intent3);
default:
}
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent=getIntent();
a=intent.getIntExtra("lai",0);
b=new int[a];di=new int[a];
initti(a);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(Main2Activity.this,android.R.layout.simple_dropdown_item_1line,ti);
ListView listView=(ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent,View view,int position,long id){
Toast.makeText(Main2Activity.this,"aaa",Toast.LENGTH_SHORT).show();
ti(position);
}
});
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "一共"+a+"题", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
Intent intent4 = new Intent(this,MyService.class);
startService(intent4);
}
private void initti(int b){
ti.clear();
SharedPreferences.Editor editor=getSharedPreferences("a",Context.MODE_PRIVATE).edit();
for (int i=1;i<=a;i++){
Random random=new Random();
int aa=random.nextInt(10);
int bb=random.nextInt(10);
int cc=random.nextInt(4);
if(cc==0){
string="第"+i+"道:"+aa+"+"+bb+"=";
dia=aa+bb;
}
if(cc==1){
string="第"+i+"道:"+aa+"-"+bb+"=";
dia=aa-bb;
}
if(cc==2){
string="第"+i+"道:"+aa+"×"+bb+"=";
dia=aa*bb;
}
if(cc==3){
string="第"+i+"道:"+aa+"÷"+bb+"=";
dia=aa/bb;
}
ti.add(string);
di[i-1]=dia;
ai="第"+i+"道答案:"+dia+" ";
editor.putString("第"+i+"道",ai);
}
editor.apply();
}
public void ti(int h){
final EditText et = new EditText(this);
final int k=h+1;
new AlertDialog.Builder(this).setTitle("请输入第"+k+"道题答案")
.setIcon(android.R.drawable.sym_def_app_icon)
.setView(et)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//按下确定键后的事件
Toast.makeText(getApplicationContext(), et.getText().toString(),Toast.LENGTH_LONG).show();
try {
b[k-1]=Integer.parseInt(et.getText().toString());
}catch (Exception e){
Toast.makeText(Main2Activity.this,"请输入正确的数字",Toast.LENGTH_SHORT).show();
}

}
}).setNegativeButton("取消",null).show();
}
public void stt(){
for (int j=0;j<a;j++){
if(di[j]==b[j]){
int l=j+1;
qi=qi+l+",";
}
}
qi=qi+" 答错的题有:";
for (int j=0;j<a;j++){
if(di[j]!=b[j]){
int l=j+1;
qi=qi+l+",";
}
}
}
public void att(){
for (int e=0;e<a;e++){
int m=e+1;
wu=wu+"第"+m+"道:"+b[e]+" ";
}
}

@Override
protected void onDestroy(){
super.onDestroy();
mp.release();//背景音乐
}

}
第三个活动:
public class Main3Activity extends AppCompatActivity {
public List<String> diaa=new ArrayList<>();
String alist=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent=getIntent();
int dia=intent.getIntExtra("aaa",0);
SharedPreferences pref=getSharedPreferences("a", Context.MODE_PRIVATE);
for (int a=1;a<=dia;a++){
alist=pref.getString("第"+a+"道","没收到");
diaa.add(alist);
}
ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(Main3Activity.this,android.R.layout.simple_dropdown_item_1line,diaa);
ListView listView=(ListView) findViewById(R.id.text) ;
listView.setAdapter(arrayAdapter);
}

}
第四个活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TextView textView=(TextView) findViewById(R.id.text1);
Intent intent=getIntent();
String dia=intent.getStringExtra("aaa");
textView.setText(dia);

FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
第五个活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main5);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TextView textView=(TextView) findViewById(R.id.text2);
Intent intent=getIntent();
String dia=intent.getStringExtra("aaa");
textView.setText(dia);
一个服务
public class MyService extends Service {
private MediaPlayer mediaPlayer = null;
private boolean isReady = false;
@Override
public void onCreate() {
super.onCreate();
mediaPlayer = MediaPlayer.create(this, R.raw.music);
if(mediaPlayer == null){
return;
}
mediaPlayer.stop();
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mp.release();
stopSelf();
return false;
}
});

try{
mediaPlayer.prepare();
isReady = true;
} catch (IOException e) {
e.printStackTrace();
isReady = false;
}

if(isReady){
mediaPlayer.setLooping(true);
}
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if(isReady && !mediaPlayer.isPlaying()){
mediaPlayer.start();
Toast.makeText(this, "开始", Toast.LENGTH_LONG).show();
}
return START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onDestroy() {
super.onDestroy();
if(mediaPlayer != null){
if(mediaPlayer.isPlaying()){
mediaPlayer.stop();
}
mediaPlayer.release();
}
}
}

 

 

 

 

18软技术图片

 

 

 

 

 

技术图片

 

 

 技术图片

 

 

 

技术图片

 

 技术图片

 

 技术图片

 

以上是关于结对项目的主要内容,如果未能解决你的问题,请参考以下文章

个人项目复用代码实现结对编程项目

结对-英文词频分析-结对项目总结

总结如何复用个人项目实现结对编程项目,以及结对编程的经验教训。

结对项目

结对编程项目报告

从结对编程初项目窥团队合作编程