基于android平台的出题软件---- 每日30题

时间:2022-12-27 12:16:05

本app共编写了3个activity,1.Mainactivity作为主界面。2.surface,用来显示随机出的题。3.showresult,用来打印所有做过的题(含结果),一个类function用来随机出题。APK下载链接http://pan.baidu.com/s/1o7fiFNG

开发时间约6个小时

具体调用、跳转如图1

基于android平台的出题软件---- 每日30题

图一  程序整体结构

接下来具体展示每一个模块。

模块1:class:function

使用java自带函数,Random.nextInt()来获得随机数,类*有两个public Long类型的数据Former和Latter,Former与Latter分别表示算术中运算符前及运算符之后的两个操作数。类*有五个函数,分别是

  • public long getRandom(int num)
  • public long setPlus(long former,long latter)
  • public long setMinus(long former,long latter)
  • public long setMutiply(long former,long latter)
  • public long setDivide(long former,long latter)

getrandom函数用来获取随机数,剩余四个用来设置加减乘除的算式,并返回运算结果。具体代码如下

 package com.example.shea.caculator;

 import java.util.Random;

 /**
* Created by shea on 2016/3/10.
*/
public class function {
public long Former=0;
public long Latter=0;
public long getRandom(int num){
int NUM=num;
Random random=new Random();
int number=random.nextInt(NUM)+1;
return number;
}
public long setPlus(long former,long latter){
return former+latter;
}
public long setMinus(long former,long latter){
long result=0;
boolean Flag=true;
do {
if (former>latter)
{
Former=former;
Latter=latter;
Flag=false;
}
else
if (former<latter)
{
Former=latter;
Latter=former;
Flag=false;
}
else {
Former=getRandom(100);
Latter=getRandom(100);
Flag=true;
} }while (Flag);
result=Former-Latter;
return result;
}
public long setMutiply(long former,long latter){
return former*latter;
}
public long setDivide(long former,long latter)
{
long result=0;
boolean FLAG=true;
do{ if (former%latter==0)
{
result=former/latter;
FLAG=false;
}
else{
Former=getRandom(100)+1;
Latter=getRandom(19)+1;
former=Former;
latter=Latter;
result=Former/Latter;
System.out.println("============"+Former+"==========="+Latter+"===================");
} }while (FLAG);
return result;
}
}

模块2:Activity:surface

本模块负责打印由function获得的随机加减乘除运算,真机运行截图如下。图4是完成三十道题之后的弹窗,此时可以选择再做30道,或者回到首页。做使用过程中,可以点击打印题目按钮获得目前做过的题目及答案,也可以点击回到主页按钮,回到主页。

本模块

public long setquestion()函数负责出题,并且使用textview呈现在surface.java上,
在其中使用int CHOOSENUM=random.nextInt(3);随机获得0-3的某个int类型的数,分别对应加减乘除,使用switch case跳转至对应出题方式。

基于android平台的出题软件---- 每日30题

图二
基于android平台的出题软件---- 每日30题

图三
基于android平台的出题软件---- 每日30题

图四

本模块代码如下:

 package com.example.shea.caculator;
//ray's work
//2013040101016
//雷翔宇 import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast; import java.util.ArrayList;
import java.util.Random; public class surface extends AppCompatActivity {
private long former=0;
private long latter=0;
private long result=0;
private long count=1;
private long RIGHT=0;
private float percentage=0;
ArrayList<String> arrayList=new ArrayList<String>(); @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.surface_layout);
final EditText editText= (EditText) findViewById(R.id.INPUTTEXT);
Button next= (Button) findViewById(R.id.next);
Button homepage= (Button) findViewById(R.id.homepage);
Button submit=(Button)findViewById(R.id.submit);
final TextView countnum= (TextView) findViewById(R.id.countnum);
final Button back2home=(Button)findViewById(R.id.backtohome);
setquestion();
back2home.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { Intent back=new Intent(surface.this,MainActivity.class);
startActivity(back);
}
}); homepage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/* Intent intent = new Intent(surface.this, MainActivity.class);
startActivity(intent);*/
StringBuffer partinfo=new StringBuffer("");
StringBuffer ALLINFO=new StringBuffer("");
for (int i = 0; i <arrayList.size() ; i++) {
//allquestions.add(arrayList.get(i));
String info= arrayList.get(i);
partinfo.append(info+"\n");
//ALLINFO.append(partinfo);
}
String allinfo=partinfo.toString();
Intent intent=new Intent(surface.this,showresult.class);
intent.putExtra("data",allinfo);
startActivity(intent); }
});
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String getnum = editText.getText().toString();
int GETNUM = Integer.valueOf(getnum);
if (GETNUM == result) {
Toast.makeText(surface.this, "回答正确~", Toast.LENGTH_SHORT).show();
RIGHT++;
} else {
Toast.makeText(surface.this,"做错了呢~请再细心计算一遍",Toast.LENGTH_SHORT).show();
} }
});
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText.setText("");
countnum.setText("已经做了"+count+"道题,做对"+RIGHT+"道\n");count++;
if (count>30) {
/*Toast.makeText(surface.this, "今天的30道题已经完成啦,你真棒!~", Toast.LENGTH_LONG).show();*/
count=30;
new AlertDialog.Builder(surface.this).setMessage("今天的任务完成啦!").setPositiveButton("查看今天的题目", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
StringBuffer partinfo=new StringBuffer("");
StringBuffer ALLINFO=new StringBuffer("");
for (int i = 0; i <arrayList.size() ; i++) {
//allquestions.add(arrayList.get(i));
String info= arrayList.get(i);
partinfo.append(info+"\n");
//ALLINFO.append(partinfo);
}
String allinfo=partinfo.toString();
Intent intent=new Intent(surface.this,showresult.class);
intent.putExtra("data",allinfo);
startActivity(intent);
}
}).setNegativeButton("再来三十道!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
count=1;
countnum.setText("");
setquestion();
}
}).create().show(); }
else
result=setquestion();
}
}); }
public long setquestion(){
TextView textView= (TextView) findViewById(R.id.textView);
function myfunc=new function();
former=myfunc.getRandom(100)+1;
latter=myfunc.getRandom(100)+1;
Random random=new Random();
int CHOOSENUM=random.nextInt(3);
//int CHOOSENUM = 1;
switch (CHOOSENUM)
{
case 0:{result=myfunc.setPlus(former,latter);
textView.setText(former + "+" + latter+"=");
String text=former + "+" + latter+"="+result;
arrayList.add(text);
}
break;
case 1:{result=myfunc.setDivide(former,latter);
textView.setText(myfunc.Former + "÷" + myfunc.Latter+"=");
String text=myfunc.Former + "÷" + myfunc.Latter+"="+result;
arrayList.add(text);
}
break;
case 2:{
result=myfunc.setMinus(former,latter);
textView.setText(myfunc.Former + "-" + myfunc.Latter+"=");
String text=myfunc.Former + "-" + myfunc.Latter+"="+result;
arrayList.add(text);
}
break;
case 3:{
result=myfunc.setMutiply(former,latter);
textView.setText(myfunc.Former + "×" + myfunc.Latter+"=");
String text=myfunc.Former + "×" + myfunc.Latter+"="+result;
arrayList.add(text);
}
break;
}
return result; }
}

模块3 Activity showresult

本模块负责打印已经做过的所有题目,因为在ACTIVITY:surface中使用intent进行跳转,故使用intent的putextra方法传递所有题目数据,在activity中添加了scrollview及嵌套的textview来展示结果。效果图如下基于android平台的出题软件---- 每日30题

本模块代码如下

 package com.example.shea.caculator;
//ray's work
//2013040101016
//雷翔宇 import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView; import java.util.ArrayList; public class showresult extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_showresult);
Button back2homepage= (Button) findViewById(R.id.back2homepage);
TextView textview= (TextView) findViewById(R.id.textView2);
Intent i=getIntent();
String info=i.getStringExtra("data");
textview.setText(info);
back2homepage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent back2homepage=new Intent(showresult.this,MainActivity.class);
startActivity(back2homepage);
}
});
}
}

因时间关系,程序内存在一些错误未能及时更正,还请海涵。

基于android平台的出题软件---- 每日30题

基于android平台的出题软件---- 每日30题