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

开发时间约6个小时

具体调用、跳转如图1

图一  程序整体结构

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

模块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跳转至对应出题方式。

图二

图三

图四

本模块代码如下:

 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来展示结果。效果图如下

本模块代码如下

 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题的更多相关文章

  1. 基于android平台的斗地主AI

    本软件是基于android平台的斗地主AI,我们在源代码的基础之上,旨在改进AI的算法,使玩家具有更丰富的体验感,让NPC可以更为智能. (一)玩法解析: (1)发牌和叫牌:一副扑克54张,先为每个人 ...

  2. 基于Android 平台简易即时通讯的研究与设计[转]

    摘要:论文简单介绍Android 平台的特性,主要阐述了基于Android 平台简易即时通讯(IM)的作用和功能以及实现方法.(复杂的通讯如引入视频音频等可以考虑AnyChat SDK~)关键词:An ...

  3. 基于Android平台的会议室管理系统具体设计说明书

    会议室管理系统具体设计说明书 第一部分  引言 1.编写目的 本说明对会议室管理系统项目的各模块.页面.脚本分别进行了实现层面上的要求和说明. 软件开发小组的产品实现成员应该阅读和參考本说明进行代码的 ...

  4. 基于Android的闹钟的软件

    一.本课题要求:设计一个基于Android的闹钟的软件. 实现的功能有:能通过界面设置闹钟的启动条件建立后台服务进程,当满足触发条件时,闹钟响应相应事件. 二.需求分析 该课题实现在手机操作系统And ...

  5. 项目:Android平台txt阅读软件

    项目:Android平台txt阅读软件 项目组成员:20145107李长达.20145110屠轶成.20145120黄玄曦.20145122程智崟 Need: 从古至今,阅读都是人类生活中的一大部分, ...

  6. 基于Android平台的简易人脸检测库

    代码地址如下:http://www.demodashi.com/demo/12135.html ViseFace 简易人脸检测库,不依赖三方库,可快速接入人脸检测功能. 项目依赖:compile 'c ...

  7. 基于ANDROID平台,U3D对蓝牙手柄键值的获取

    对于ANDROID平台,物理蓝牙手柄已被封装,上层应用不可见,也就是说对于上层应用,不区分蓝牙手柄还是其它手柄: 完成蓝牙手柄和ANDROID手机的蓝牙连接后,即可以UNITY3D中获取其键值: 在U ...

  8. 结对编程--基于android平台的黄金点游戏(2.0版本)

    在昨天上传完博客之后发现一个重大的bug...故在此推出2.0版本. 博文详情见:http://www.cnblogs.com/RayShea/p/5372398.html coding地址:http ...

  9. 结对编程--基于android平台的黄金点游戏

    游戏内容: 阿超的课都是下午两点钟,这时班上不少的同学都昏昏欲睡,为了让大家兴奋起来,阿超让同学玩一个叫“黄金点”的游戏: N个同学(N通常大于10),每人写一个0~100之间的有理数 (不包括0或1 ...

随机推荐

  1. play(1) 第一个简单的应用

    去年去了一家公司,公司要求要回使用play,所以在几天的时间内猛学习了一段时间play,发现play!有很多优点:简单,小巧,高开发效率,集成很多功能,容易调试.现在虽然已经不在那家公司,没有使用pl ...

  2. c++ 基础一

    // my first program in C++ #include <iostream.h> using namespace std; int main() { cout <&l ...

  3. 关闭键盘导致tableView:didSelectRowAtIndexPath:失效解决办法

    今天公司的小兄弟问了tableView:didSelectRowAtIndexPath:不能执行的问题. 从经验看觉得可能是控制器没有成为tableView的代理所致.但代码中已经添加了代码 _tab ...

  4. Android性能测试工具APT使用指南

    腾讯的安卓平台高效的性能测试工具APT(Android Performance Testing Tools),适用于开发自测和定位性能瓶颈,帮助测试人员完成性能基准测试.竞品测试. APT提供了CPU ...

  5. Disable the screen switching about VI

    If you want to disable the screen switching, and you don't want tochange your termcap, you can add t ...

  6. Eclipse/JavaWeb (一)三大框架之struts框架 持续更新中...

    最近主要把javaweb的三大框架过一遍. (一)发展历史 传统的Java Web应用程序是采用JSP+Servlet+Javabean来实现的,这种模式实现了最基本的MVC分层,使得程序分为几层,有 ...

  7. 黑马----JAVA迭代器详解

    JAVA迭代器详解 1.Interable.Iterator和ListIterator 1)迭代器生成接口Interable,用于生成一个具体迭代器 public interface Iterable ...

  8. 7、provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错

    在建立与服务器的连接时出错.在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败.(provider: SQL 网络接口, error ...

  9. 解决表单(搜索框)回车的时候直接提交了表单不运行js的问题

    我想在搜索输入框中输入关键词后回车,先运行一段js,然后在提交表单,而默认情况下回车的时候也会出发表单的提交所有没法等js运行完成,故利用 onkeydown="if(event.keyCo ...

  10. 09——绝不在构造和析构函数中调用virtual函数

    在base class构造期间,virtual函数不是virtual函数. 构造函数.析构函数中不要调用virtual函数.