Mainactivity类:
package com.example.XXSCYS;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.content.Intent;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.EditText;import android.widget.TextView;public class MainActivity extends Activity { public static final String FILENAME = "setting.set"; public static final String FILENAME1 = "mima.set"; public static final String FILENAME0 = "zancun.set"; private EditText et; private EditText et1; private EditText et2; TextView text; String c; OnClickListener listener1 = null;//监听器初始化 OnClickListener listener2 = null; OnClickListener listener3 = null; OnClickListener listener4 = null; String a; String b; Button button1;//定义按钮 TextView textView; TextView textView1; CheckBox CheckBox; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text=(TextView) findViewById(R.id.editText3); b=readFiles0(); text.setText(b); //登录 listener1 = new OnClickListener() { public void onClick(View v) { et=(EditText)findViewById(R.id.editText2); et1=(EditText)findViewById(R.id.editText3); c=readFiles1(); a=readFiles(); if(et.getText().toString().equals(c) && et1.getText().toString().equals(a)){ /*AlertDialog.Builder builder = new Builder(MainActivity.this); builder.setTitle("信息提醒" ) ; builder.setMessage("密码输入正确!!" ) ; builder.setPositiveButton("确定" , null ); */ et.setText(""); Intent intent = new Intent(MainActivity.this, onectivity.class); startActivity(intent); //builder.show(); } else{ AlertDialog.Builder builder = new Builder(MainActivity.this); builder.setTitle("信息提醒" ) ; builder.setMessage("密码错误!请重新输入!") ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); } } }; //注册 listener2 = new OnClickListener() { public void onClick(View v) { setTitle("注册"); Intent intent1 = new Intent(MainActivity.this, zhuce.class); startActivity(intent1); } }; //忘记密码 listener3 = new OnClickListener() { public void onClick(View v) { a=readFiles(); AlertDialog.Builder builder = new Builder(MainActivity.this); builder.setTitle("信息提醒" ) ; builder.setMessage("请联系客服光大大设计者拿回密码!") ; builder.setPositiveButton("确定" , null ); builder.show(); //et.setText(""); } }; //记住我 listener4 = new OnClickListener() { public void onClick(View v) { et2=(EditText)findViewById(R.id.editText3); writeFiles0(et2.getText().toString()); } }; setContentView(R.layout.activity_main); button1 = (Button) findViewById(R.id.denglu); button1.setOnClickListener(listener1); textView = (TextView) findViewById(R.id.zhuce); textView.setOnClickListener(listener2); textView1 = (TextView) findViewById(R.id.wangji); textView1.setOnClickListener(listener3); CheckBox = (CheckBox) findViewById(R.id.jizhu); CheckBox.setOnClickListener(listener4); } // 保存文件暂时保存账号内容 private void writeFiles0(String content) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos0 = openFileOutput(FILENAME0, Context.MODE_PRIVATE); fos0.write(content.getBytes()); fos0.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取文件内容 private String readFiles0() { String content = null ; try { FileInputStream fis = openFileInput(FILENAME0); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content; } // 读取文件内容 private String readFiles() { String content = null ; try { FileInputStream fis = openFileInput(FILENAME); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content; } // 读取文件内容 private String readFiles1() { String content1 = null ; try { FileInputStream fis = openFileInput(FILENAME1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content1 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content1; } }
注册类:
package com.example.XXSCYS; import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import android.annotation.SuppressLint;import android.app.Activity; import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.content.Intent;import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText; import android.widget.TextView;public class zhuce extends Activity{ private EditText zhanghao; private EditText mima; private EditText QRmima; private EditText nicheng; private Button Btn; private int dengji=0; private int money=100; private int daoju=0; //private TextView contentView; String xinxi; public static final String FILENAME = "setting.set"; public static final String FILENAME1 = "mima.set"; public static final String FILENAME2 = "xinxi.set"; public static final String FILENAME3 = "dengji.set"; public static final String FILENAME4 = "money.set"; public static final String FILENAME5 = "daoju.set"; OnClickListener listener1 = null;//监听器初始化 EditText editText; @SuppressLint("CutPasteId") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.zhuce); zhanghao = (EditText) findViewById(R.id.editText1); mima = (EditText) findViewById(R.id.editText2); QRmima = (EditText) findViewById(R.id.editText3); nicheng = (EditText) findViewById(R.id.editText4); Btn = (Button) findViewById(R.id.button1); // contentView = (TextView) findViewById(R.id.contentview); Btn.setOnClickListener(new OperateOnClickListener()); } class OperateOnClickListener implements OnClickListener { @Override public void onClick(View v) { writeFiles(zhanghao.getText().toString()); writeFiles1(mima.getText().toString()); //writeFiles(QRmima.getText().toString()); writeFiles2(nicheng.getText().toString()); writeFiles3(""+dengji); writeFiles4(""+money); writeFiles5(""+daoju); xinxi=readFiles2(); if(mima.getText().toString().equals(QRmima.getText().toString())){ AlertDialog.Builder builder = new Builder(zhuce.this); builder.setTitle("注册成功" ) ; builder.setMessage("昵称"+xinxi+"\n"+"等级"+dengji+"\n"+"金币"+money ) ; builder.setPositiveButton("确定" , null ); builder.show(); zhanghao.setText(""); mima.setText(""); QRmima.setText(""); nicheng.setText(""); System.out.println(getFilesDir()); zhuce.this.finish(); } else{ AlertDialog.Builder builder = new Builder(zhuce.this); builder.setTitle("信息提醒" ) ; builder.setMessage("密码确认不符!请重新输入!") ; builder.setPositiveButton("确定" , null ); builder.show(); mima.setText(""); QRmima.setText(""); } } } // 保存文件内容(账号) private void writeFiles(String content) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(content.getBytes()); fos.close(); } catch (Exception e) { e.printStackTrace(); } } // 保存文件内容 (密码) private void writeFiles1(String content1) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos1 = openFileOutput(FILENAME1, Context.MODE_PRIVATE); fos1.write(content1.getBytes()); fos1.close(); } catch (Exception e) { e.printStackTrace(); } } // 保存文件内容 (昵称) private void writeFiles2(String content2) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos2 = openFileOutput(FILENAME2, Context.MODE_PRIVATE); fos2.write(content2.getBytes()); fos2.close(); } catch (Exception e) { e.printStackTrace(); } } // 保存文件内容 (等级) private void writeFiles3(String content3) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos3 = openFileOutput(FILENAME3, Context.MODE_PRIVATE); fos3.write(content3.getBytes()); fos3.close(); } catch (Exception e) { e.printStackTrace(); } } // 保存文件内容 (金币) private void writeFiles4(String content4) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos4 = openFileOutput(FILENAME4, Context.MODE_PRIVATE); fos4.write(content4.getBytes()); fos4.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取昵称 private String readFiles2() { String content2 = null ; try { FileInputStream fis = openFileInput(FILENAME2); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content2 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content2; } // 保存文件内容 private void writeFiles5(String content5) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos5 = openFileOutput(FILENAME5, Context.MODE_PRIVATE); fos5.write(content5.getBytes()); fos5.close(); } catch (Exception e) { e.printStackTrace(); } } }
登陆类(启动页面):
package com.example.XXSCYS;import android.annotation.SuppressLint;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;import android.view.Window;import android.widget.Button;import android.widget.PopupMenu;import android.widget.RadioGroup;import android.widget.TabHost;import android.widget.RadioGroup.OnCheckedChangeListener;public class onectivity extends TabActivity implements OnCheckedChangeListener{ private RadioGroup mainTab; private TabHost tabhost; private Intent a; private Intent xinxi; private Intent shangcheng; @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.onectivity); final Button btn=(Button)findViewById(R.id.dati); final PopupMenu popupMenu=new PopupMenu(this, btn); popupMenu.inflate(R.menu.main); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub popupMenu.show(); } }); //菜单单击响应 popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){ @Override public boolean onMenuItemClick(MenuItem item){ switch(item.getItemId()){ case R.id.jiafa: setTitle("加法"); Intent intent1 = new Intent(onectivity.this, jiafa.class); startActivity(intent1); break; case R.id.jianfa: setTitle("减法"); Intent intent2 = new Intent(onectivity.this, jianfa.class); startActivity(intent2); break; case R.id.chengfa: setTitle("乘法"); Intent intent3 = new Intent(onectivity.this, chengfa.class); startActivity(intent3); break; case R.id.chufa: setTitle("除法"); Intent intent4 = new Intent(onectivity.this, chufa.class); startActivity(intent4); break; case R.id.hunhe: setTitle("混合运算"); Intent intent5 = new Intent(onectivity.this, hunhe.class); startActivity(intent5); break; } return false; } }); mainTab=(RadioGroup)findViewById(R.id.main_tab); mainTab.setOnCheckedChangeListener(this); tabhost = getTabHost(); a= new Intent(this, a.class); tabhost.addTab(tabhost.newTabSpec("a") .setIndicator(getResources().getString(R.string.xinxi), getResources().getDrawable(R.drawable.xinxi)) .setContent(a)); xinxi= new Intent(this, xinxi.class); tabhost.addTab(tabhost.newTabSpec("xinxi") .setIndicator(getResources().getString(R.string.xinxi), getResources().getDrawable(R.drawable.xinxi)) .setContent(xinxi)); shangcheng = new Intent(this,shangcheng.class); tabhost.addTab(tabhost.newTabSpec("shangcheng") .setIndicator(getResources().getString(R.string.shangcheng), getResources().getDrawable(R.drawable.shangcheng)) .setContent(shangcheng)); } @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch(checkedId){ case R.id.xinxi: this.tabhost.setCurrentTabByTag("xinxi"); break; case R.id.shangcheng: this.tabhost.setCurrentTabByTag("shangcheng"); break; case R.id.tuichu: onectivity.this.finish(); break; } } }
加法类:
package com.example.XXSCYS;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class jiafa extends Activity { public static final String FILENAME3 = "dengji.set"; public static final String FILENAME4 = "money.set"; public static final String FILENAME5 = "daoju.set"; private int money; private float dengji; private int daoju; private EditText et; TextView text; OnClickListener listener1 = null;//监听器初始化 OnClickListener listener2 = null; OnClickListener listener3 = null; OnClickListener listener4 = null; Button button1;//定义按钮 Button button2; Button button3; Button button4; double c; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);; setContentView(R.layout.jiafa); listener1 = new OnClickListener() { public void onClick(View v) { int a=(int)(Math.random()*(-5))+10; int b=(int)(Math.random()*(-5))+20; text=(TextView) findViewById(R.id.editText3); text.setText(a+"+"+b+"=?"); c=a+b; } }; listener2 = new OnClickListener() { public void onClick(View v) { String m; String n; m=readFiles4(); n=readFiles3(); final int i = Integer.parseInt(m); final float j = Float.parseFloat(n); et=(EditText)findViewById(R.id.editText2); if(Integer.parseInt(et.getText().toString())==c){ AlertDialog.Builder builder = new Builder(jiafa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("恭喜啦,回答正确!!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i+10; dengji=(float) (j+0.1); } else{ AlertDialog.Builder builder = new Builder(jiafa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("很遗憾,回答错误!加油哦!正确答案为:"+c ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i-5; } writeFiles4(""+money); writeFiles3(""+dengji); } }; listener3 = new OnClickListener() { public void onClick(View v) { int a=(int)(Math.random()*(-5))+10; int b=(int)(Math.random()*(-5))+20; text=(TextView) findViewById(R.id.editText3); text.setText(a+"+"+b+"=?"); c=a+b; } }; listener4 = new OnClickListener() { public void onClick(View v) { String o; o=readFiles5(); final int p = Integer.parseInt(o); if(o.equals("0")) { AlertDialog.Builder builder = new Builder(jiafa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("您的道具余额不足,请去商城购买道具!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); } else{ AlertDialog.Builder builder = new Builder(jiafa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("正确答案为:"+c+"\n"+"您用掉了一个道具" ) ; builder.setPositiveButton("确定" , null ); builder.show(); daoju=p-1; writeFiles5(""+daoju); } } }; setContentView(R.layout.jiafa); button1 = (Button) findViewById(R.id.start); button1.setOnClickListener(listener1); button2 = (Button) findViewById(R.id.tijiao); button2.setOnClickListener(listener2); button3 = (Button) findViewById(R.id.next); button3.setOnClickListener(listener3); button4 = (Button) findViewById(R.id.daoju); button4.setOnClickListener(listener4); } // 读取等级 private String readFiles3() { String content3 = null ; try { FileInputStream fis = openFileInput(FILENAME3); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content3 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content3; } // 保存文件内容 private void writeFiles3(String content3) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos3 = openFileOutput(FILENAME3, Context.MODE_PRIVATE); fos3.write(content3.getBytes()); fos3.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取金币 private String readFiles4() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 保存文件内容 private void writeFiles4(String content4) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos4 = openFileOutput(FILENAME4, Context.MODE_PRIVATE); fos4.write(content4.getBytes()); fos4.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取道具数 private String readFiles5() { String content5 = null ; try { FileInputStream fis = openFileInput(FILENAME5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content5 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content5; } // 保存文件内容 private void writeFiles5(String content5) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos5 = openFileOutput(FILENAME5, Context.MODE_PRIVATE); fos5.write(content5.getBytes()); fos5.close(); } catch (Exception e) { e.printStackTrace(); } } }
减法类:
package com.example.XXSCYS;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class jianfa extends Activity { public static final String FILENAME3 = "dengji.set"; public static final String FILENAME4 = "money.set"; public static final String FILENAME5 = "daoju.set"; private int money; private float dengji; private int daoju; private EditText et; TextView text; OnClickListener listener1 = null;//监听器初始化 OnClickListener listener2 = null; OnClickListener listener3 = null; OnClickListener listener4 = null; Button button1;//定义按钮 Button button2; Button button3; Button button4; double c; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);; setContentView(R.layout.jiafa); listener1 = new OnClickListener() { public void onClick(View v) { int a=(int)(Math.random()*(-5))+20; int b=(int)(Math.random()*(-5))+10; text=(TextView) findViewById(R.id.editText3); text.setText(a+"-"+b+"=?"); c=a-b; } }; listener2 = new OnClickListener() { public void onClick(View v) { String m; String n; m=readFiles4(); n=readFiles3(); final int i = Integer.parseInt(m); final float j = Float.parseFloat(n); et=(EditText)findViewById(R.id.editText2); if(Integer.parseInt(et.getText().toString())==c){ AlertDialog.Builder builder = new Builder(jianfa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("恭喜啦,回答正确!!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i+10; dengji=(float) (j+0.1); } else{ AlertDialog.Builder builder = new Builder(jianfa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("很遗憾,回答错误!加油哦!正确答案为:"+c ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i-5; } writeFiles4(""+money); writeFiles3(""+dengji); } }; listener3 = new OnClickListener() { public void onClick(View v) { int a=(int)(Math.random()*(-5))+20; int b=(int)(Math.random()*(-5))+10; text=(TextView) findViewById(R.id.editText3); text.setText(a+"-"+b+"=?"); c=a-b; } }; listener4 = new OnClickListener() { public void onClick(View v) { String o; o=readFiles5(); final int p = Integer.parseInt(o); if(o.equals("0")) { AlertDialog.Builder builder = new Builder(jianfa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("您的道具余额不足,请去商城购买道具!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); } else{ AlertDialog.Builder builder = new Builder(jianfa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("正确答案为:"+c+"\n"+"您用掉了一个道具" ) ; builder.setPositiveButton("确定" , null ); builder.show(); daoju=p-1; writeFiles5(""+daoju); } } }; setContentView(R.layout.jiafa); button1 = (Button) findViewById(R.id.start); button1.setOnClickListener(listener1); button2 = (Button) findViewById(R.id.tijiao); button2.setOnClickListener(listener2); button3 = (Button) findViewById(R.id.next); button3.setOnClickListener(listener3); button4 = (Button) findViewById(R.id.daoju); button4.setOnClickListener(listener4); } // 读取等级 private String readFiles3() { String content3 = null ; try { FileInputStream fis = openFileInput(FILENAME3); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content3 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content3; } // 保存文件内容 private void writeFiles3(String content3) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos3 = openFileOutput(FILENAME3, Context.MODE_PRIVATE); fos3.write(content3.getBytes()); fos3.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取金币 private String readFiles4() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 保存文件内容 private void writeFiles4(String content4) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos4 = openFileOutput(FILENAME4, Context.MODE_PRIVATE); fos4.write(content4.getBytes()); fos4.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取道具数 private String readFiles5() { String content5 = null ; try { FileInputStream fis = openFileInput(FILENAME5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content5 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content5; } // 保存文件内容 private void writeFiles5(String content5) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos5 = openFileOutput(FILENAME5, Context.MODE_PRIVATE); fos5.write(content5.getBytes()); fos5.close(); } catch (Exception e) { e.printStackTrace(); } } }
乘法类:
package com.example.XXSCYS;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class chengfa extends Activity { public static final String FILENAME3 = "dengji.set"; public static final String FILENAME4 = "money.set"; public static final String FILENAME5 = "daoju.set"; private int money; private float dengji; private int daoju; private EditText et; TextView text; OnClickListener listener1 = null;//监听器初始化 OnClickListener listener2 = null; OnClickListener listener3 = null; OnClickListener listener4 = null; Button button1;//定义按钮 Button button2; Button button3; Button button4; double c; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);; setContentView(R.layout.jiafa); listener1 = new OnClickListener() { public void onClick(View v) { int a=(int)(Math.random()*(-5))+10; int b=(int)(Math.random()*(-5))+20; text=(TextView) findViewById(R.id.editText3); text.setText(a+"*"+b+"=?"); c=a*b; } }; listener2 = new OnClickListener() { public void onClick(View v) { String m; String n; m=readFiles4(); n=readFiles3(); final int i = Integer.parseInt(m); final float j = Float.parseFloat(n); et=(EditText)findViewById(R.id.editText2); if(Integer.parseInt(et.getText().toString())==c){ AlertDialog.Builder builder = new Builder(chengfa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("恭喜啦,回答正确!!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i+10; dengji=(float) (j+0.1); } else{ AlertDialog.Builder builder = new Builder(chengfa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("很遗憾,回答错误!加油哦!正确答案为:"+c ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i-5; } writeFiles4(""+money); writeFiles3(""+dengji); } }; listener3 = new OnClickListener() { public void onClick(View v) { int a=(int)(Math.random()*(-5))+10; int b=(int)(Math.random()*(-5))+20; text=(TextView) findViewById(R.id.editText3); text.setText(a+"*"+b+"=?"); c=a*b; } }; listener4 = new OnClickListener() { public void onClick(View v) { String o; o=readFiles5(); final int p = Integer.parseInt(o); if(o.equals("0")) { AlertDialog.Builder builder = new Builder(chengfa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("您的道具余额不足,请去商城购买道具!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); } else{ AlertDialog.Builder builder = new Builder(chengfa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("正确答案为:"+c+"\n"+"您用掉了一个道具" ) ; builder.setPositiveButton("确定" , null ); builder.show(); daoju=p-1; writeFiles5(""+daoju); } } }; setContentView(R.layout.jiafa); button1 = (Button) findViewById(R.id.start); button1.setOnClickListener(listener1); button2 = (Button) findViewById(R.id.tijiao); button2.setOnClickListener(listener2); button3 = (Button) findViewById(R.id.next); button3.setOnClickListener(listener3); button4 = (Button) findViewById(R.id.daoju); button4.setOnClickListener(listener4); } // 读取等级 private String readFiles3() { String content3 = null ; try { FileInputStream fis = openFileInput(FILENAME3); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content3 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content3; } // 保存文件内容 private void writeFiles3(String content3) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos3 = openFileOutput(FILENAME3, Context.MODE_PRIVATE); fos3.write(content3.getBytes()); fos3.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取金币 private String readFiles4() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 保存文件内容 private void writeFiles4(String content4) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos4 = openFileOutput(FILENAME4, Context.MODE_PRIVATE); fos4.write(content4.getBytes()); fos4.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取道具数 private String readFiles5() { String content5 = null ; try { FileInputStream fis = openFileInput(FILENAME5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content5 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content5; } // 保存文件内容 private void writeFiles5(String content5) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos5 = openFileOutput(FILENAME5, Context.MODE_PRIVATE); fos5.write(content5.getBytes()); fos5.close(); } catch (Exception e) { e.printStackTrace(); } } }
除法类:
package com.example.XXSCYS;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class chufa extends Activity { public static final String FILENAME3 = "dengji.set"; public static final String FILENAME4 = "money.set"; public static final String FILENAME5 = "daoju.set"; private int money; private float dengji; private int daoju; private EditText et; TextView text; OnClickListener listener1 = null;//监听器初始化 OnClickListener listener2 = null; OnClickListener listener3 = null; OnClickListener listener4 = null; Button button1;//定义按钮 Button button2; Button button3; Button button4; double c; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);; setContentView(R.layout.jiafa); listener1 = new OnClickListener() { public void onClick(View v) { int a=(int)(Math.random()*(-5))+20; int b=(int)(Math.random()*(-5))+10; text=(TextView) findViewById(R.id.editText3); text.setText(a+"/"+b+"=?"); c=a/b; } }; listener2 = new OnClickListener() { public void onClick(View v) { String m; String n; m=readFiles4(); n=readFiles3(); final int i = Integer.parseInt(m); final float j = Float.parseFloat(n); et=(EditText)findViewById(R.id.editText2); if(Integer.parseInt(et.getText().toString())==c){ AlertDialog.Builder builder = new Builder(chufa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("恭喜啦,回答正确!!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i+10; dengji=(float) (j+0.1); } else{ AlertDialog.Builder builder = new Builder(chufa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("很遗憾,回答错误!加油哦!正确答案为:"+c ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i-5; } writeFiles4(""+money); writeFiles3(""+dengji); } }; listener3 = new OnClickListener() { public void onClick(View v) { int a=(int)(Math.random()*(-5))+20; int b=(int)(Math.random()*(-5))+10; text=(TextView) findViewById(R.id.editText3); text.setText(a+"/"+b+"=?"); c=a/b; } }; listener4 = new OnClickListener() { public void onClick(View v) { String o; o=readFiles5(); final int p = Integer.parseInt(o); if(o.equals("0")) { AlertDialog.Builder builder = new Builder(chufa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("您的道具余额不足,请去商城购买道具!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); } else{ AlertDialog.Builder builder = new Builder(chufa.this); builder.setTitle("信息提醒" ) ; builder.setMessage("正确答案为:"+c+"\n"+"您用掉了一个道具" ) ; builder.setPositiveButton("确定" , null ); builder.show(); daoju=p-1; writeFiles5(""+daoju); } } }; setContentView(R.layout.jiafa); button1 = (Button) findViewById(R.id.start); button1.setOnClickListener(listener1); button2 = (Button) findViewById(R.id.tijiao); button2.setOnClickListener(listener2); button3 = (Button) findViewById(R.id.next); button3.setOnClickListener(listener3); button4 = (Button) findViewById(R.id.daoju); button4.setOnClickListener(listener4); } // 读取等级 private String readFiles3() { String content3 = null ; try { FileInputStream fis = openFileInput(FILENAME3); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content3 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content3; } // 保存文件内容 private void writeFiles3(String content3) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos3 = openFileOutput(FILENAME3, Context.MODE_PRIVATE); fos3.write(content3.getBytes()); fos3.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取金币 private String readFiles4() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 保存文件内容 private void writeFiles4(String content4) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos4 = openFileOutput(FILENAME4, Context.MODE_PRIVATE); fos4.write(content4.getBytes()); fos4.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取道具数 private String readFiles5() { String content5 = null ; try { FileInputStream fis = openFileInput(FILENAME5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content5 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content5; } // 保存文件内容 private void writeFiles5(String content5) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos5 = openFileOutput(FILENAME5, Context.MODE_PRIVATE); fos5.write(content5.getBytes()); fos5.close(); } catch (Exception e) { e.printStackTrace(); } } }
混合运算类:
package com.example.XXSCYS;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class hunhe extends Activity { public static final String FILENAME3 = "dengji.set"; public static final String FILENAME4 = "money.set"; public static final String FILENAME5 = "daoju.set"; private int money; private float dengji; private int daoju; int a,x,y,o,p,j1,j2; float z,q,s1,s2,f,n; private EditText et; TextView text; OnClickListener listener1 = null;//监听器初始化 OnClickListener listener2 = null; OnClickListener listener3 = null; OnClickListener listener4 = null; Button button1;//定义按钮 Button button2; Button button3; Button button4; //double c; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);; setContentView(R.layout.jiafa); listener1 = new OnClickListener() { public void onClick(View v) { text=(TextView) findViewById(R.id.editText3); x=(int)(1+Math.random()*100); y=(int)(1+Math.random()*100); o=(int)(1+Math.random()*100); p=(int)(1+Math.random()*100); a=(int)(1+Math.random()*16); j1=x*y; j2=o*p; s1=x/y; s2=o/p; switch (a) { case 1: text.setText("("+x+"+"+y+")"+"*"+"("+o+"+"+p+")"+"="); z=x+y; q=o+p; f=z*q; break; case 2: z=x-y; if(z<0) {text.setText("("+y+"-"+x+")"+"*"+"("+o+"+"+p+")"+"="); z=-z; } else { text.setText("("+x+"-"+y+")"+"*"+"("+o+"+"+p+")"+"="); } q=o+p; f=z*q; break; case 3: z=x-y; if(z>0) text.setText("("+x+"-"+y+")"+"/"+"("+o+"+"+p+")"+"="); else { text.setText("("+y+"-"+x+")"+"/"+"("+o+"+"+p+")"+"="); z=-z; } q=o+p; f=q*z; break; case 4: text.setText("("+x+"+"+y+")"+"/"+"("+o+"+"+p+")"+"="); f=(x+y)/(o+p); break; case 5: if(o==p) o++; z=x-y; q=o-p; if(z>0 && q>0) text.setText("("+x+"-"+y+")"+"/"+"("+o+"-"+p+")"+"="); if(z>0 && q<0) { text.setText("("+x+"-"+y+")"+"/"+"("+p+"-"+o+")"+"="); q=-q; } if(z<0 && q>0) {text.setText("("+y+"-"+x+")"+"/"+"("+o+"-"+p+")"+"="); z=-z; } if(z<0 && q<0) { text.setText("("+y+"-"+x+")"+"/"+"("+p+"-"+o+")"+"="); z=-z; q=-q; } f=z/q; break; case 6: q=o-p; z=x+y; if(q>0) text.setText("("+x+"+"+y+")"+"/"+"("+o+"-"+p+")"+"="); else {text.setText("("+x+"+"+y+")"+"/"+"("+p+"-"+o+")"+"="); q=-q; } f=z/q; break; case 7: z=x-y; q=o+p; if(z>0) text.setText("("+x+"-"+y+")"+"*"+"("+o+"+"+p+")"+"="); else { text.setText("("+y+"-"+x+")"+"*"+"("+o+"+"+p+")"+"="); z=-z; } f=z*q; break; case 8: q=o-p; z=x+y; if(q>0) text.setText("("+x+"+"+y+")"+"*"+"("+o+"-"+p+")"+"="); else { text.setText("("+x+"+"+y+")"+"*"+"("+o+"-"+p+")"+"="); q=-q; } f=z*q; break; case 9: if(j1>j2) {text.setText(x+"*"+y+"-"+o+"*"+p+"="); f=j1-j2; } else { text.setText(o+"*"+p+"-"+x+"*"+y+"="); f=j2-j1; } break; case 10: if(j1>s2) { text.setText(x+"*"+y+"-"+o+"/"+p+"="); f=j1-s2; } else { text.setText(o+"/"+p+"-"+x+"*"+y+"="); f=s2-j1; } break; case 11: if(s1>j2) { text.setText(x+"/"+y+"-"+o+"*"+p+"="); f=s1-j2; } else { text.setText(o+"*"+p+"-"+x+"/"+y+"="); f=j2-s1; } break; case 12: f=s1-s2; if(f>0) { text.setText(x+"/"+y+"-"+o+"/"+p+"="); } if(f<0) { text.setText(o+"/"+p+"-"+x+"/"+y+"="); f=s2-s1; } break; case 13: text.setText(x+"*"+y+"+"+o+"*"+p+"="); f=j1+j2; break; case 14: text.setText(x+"*"+y+"+"+o+"/"+p+"="); f=1+s2; break; case 15: text.setText(x+"/"+y+"+"+o+"*"+p+"="); f=s1+j2; break; case 16: text.setText(x+"/"+y+"+"+o+"/"+p+"="); f=s2+s1; break; default: break; } } }; listener2 = new OnClickListener() { public void onClick(View v) { String m; String n; m=readFiles4(); n=readFiles3(); final int i = Integer.parseInt(m); final float j = Float.parseFloat(n); et=(EditText)findViewById(R.id.editText2); if(Integer.parseInt(et.getText().toString())==f){ AlertDialog.Builder builder = new Builder(hunhe.this); builder.setTitle("信息提醒" ) ; builder.setMessage("恭喜啦,回答正确!!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i+10; dengji=(float) (j+0.1); } else{ AlertDialog.Builder builder = new Builder(hunhe.this); builder.setTitle("信息提醒" ) ; builder.setMessage("很遗憾,回答错误!加油哦!正确答案为:"+f ) ; builder.setPositiveButton("确定" , null ); builder.show(); et.setText(""); text.setText(""); money=i-5; } writeFiles4(""+money); writeFiles3(""+dengji); } }; listener3 = new OnClickListener() { public void onClick(View v) { text=(TextView) findViewById(R.id.editText3); x=(int)(1+Math.random()*100); y=(int)(1+Math.random()*100); o=(int)(1+Math.random()*100); p=(int)(1+Math.random()*100); a=(int)(1+Math.random()*16); j1=x*y; j2=o*p; s1=x/y; s2=o/p; switch (a) { case 1: text.setText("("+x+"+"+y+")"+"*"+"("+o+"+"+p+")"+"="); z=x+y; q=o+p; f=z*q; break; case 2: z=x-y; if(z<0) {text.setText("("+y+"-"+x+")"+"*"+"("+o+"+"+p+")"+"="); z=-z; } else { text.setText("("+x+"-"+y+")"+"*"+"("+o+"+"+p+")"+"="); } q=o+p; f=z*q; break; case 3: z=x-y; if(z>0) text.setText("("+x+"-"+y+")"+"/"+"("+o+"+"+p+")"+"="); else { text.setText("("+y+"-"+x+")"+"/"+"("+o+"+"+p+")"+"="); z=-z; } q=o+p; f=q*z; break; case 4: text.setText("("+x+"+"+y+")"+"/"+"("+o+"+"+p+")"+"="); f=(x+y)/(o+p); break; case 5: if(o==p) o++; z=x-y; q=o-p; if(z>0 && q>0) text.setText("("+x+"-"+y+")"+"/"+"("+o+"-"+p+")"+"="); if(z>0 && q<0) { text.setText("("+x+"-"+y+")"+"/"+"("+p+"-"+o+")"+"="); q=-q; } if(z<0 && q>0) {text.setText("("+y+"-"+x+")"+"/"+"("+o+"-"+p+")"+"="); z=-z; } if(z<0 && q<0) { text.setText("("+y+"-"+x+")"+"/"+"("+p+"-"+o+")"+"="); z=-z; q=-q; } f=z/q; break; case 6: q=o-p; z=x+y; if(q>0) text.setText("("+x+"+"+y+")"+"/"+"("+o+"-"+p+")"+"="); else {text.setText("("+x+"+"+y+")"+"/"+"("+p+"-"+o+")"+"="); q=-q; } f=z/q; break; case 7: z=x-y; q=o+p; if(z>0) text.setText("("+x+"-"+y+")"+"*"+"("+o+"+"+p+")"+"="); else { text.setText("("+y+"-"+x+")"+"*"+"("+o+"+"+p+")"+"="); z=-z; } f=z*q; break; case 8: q=o-p; z=x+y; if(q>0) text.setText("("+x+"+"+y+")"+"*"+"("+o+"-"+p+")"+"="); else { text.setText("("+x+"+"+y+")"+"*"+"("+o+"-"+p+")"+"="); q=-q; } f=z*q; break; case 9: if(j1>j2) {text.setText(x+"*"+y+"-"+o+"*"+p+"="); f=j1-j2; } else { text.setText(o+"*"+p+"-"+x+"*"+y+"="); f=j2-j1; } break; case 10: if(j1>s2) { text.setText(x+"*"+y+"-"+o+"/"+p+"="); f=j1-s2; } else { text.setText(o+"/"+p+"-"+x+"*"+y+"="); f=s2-j1; } break; case 11: if(s1>j2) { text.setText(x+"/"+y+"-"+o+"*"+p+"="); f=s1-j2; } else { text.setText(o+"*"+p+"-"+x+"/"+y+"="); f=j2-s1; } break; case 12: f=s1-s2; if(f>0) { text.setText(x+"/"+y+"-"+o+"/"+p+"="); } if(f<0) { text.setText(o+"/"+p+"-"+x+"/"+y+"="); f=s2-s1; } break; case 13: text.setText(x+"*"+y+"+"+o+"*"+p+"="); f=j1+j2; break; case 14: text.setText(x+"*"+y+"+"+o+"/"+p+"="); f=1+s2; break; case 15: text.setText(x+"/"+y+"+"+o+"*"+p+"="); f=s1+j2; break; case 16: text.setText(x+"/"+y+"+"+o+"/"+p+"="); f=s2+s1; break; default: break; } } }; listener4 = new OnClickListener() { public void onClick(View v) { String o; o=readFiles5(); final int p = Integer.parseInt(o); if(o.equals("0")) { AlertDialog.Builder builder = new Builder(hunhe.this); builder.setTitle("信息提醒" ) ; builder.setMessage("您的道具余额不足,请去商城购买道具!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); } else{ AlertDialog.Builder builder = new Builder(hunhe.this); builder.setTitle("信息提醒" ) ; builder.setMessage("正确答案为:"+f+"\n"+"您用掉了一个道具" ) ; builder.setPositiveButton("确定" , null ); builder.show(); daoju=p-1; writeFiles5(""+daoju); } } }; setContentView(R.layout.jiafa); button1 = (Button) findViewById(R.id.start); button1.setOnClickListener(listener1); button2 = (Button) findViewById(R.id.tijiao); button2.setOnClickListener(listener2); button3 = (Button) findViewById(R.id.next); button3.setOnClickListener(listener3); button4 = (Button) findViewById(R.id.daoju); button4.setOnClickListener(listener4); } // 读取等级 private String readFiles3() { String content3 = null ; try { FileInputStream fis = openFileInput(FILENAME3); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content3 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content3; } // 保存文件内容 private void writeFiles3(String content3) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos3 = openFileOutput(FILENAME3, Context.MODE_PRIVATE); fos3.write(content3.getBytes()); fos3.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取金币 private String readFiles4() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 保存文件内容 private void writeFiles4(String content4) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos4 = openFileOutput(FILENAME4, Context.MODE_PRIVATE); fos4.write(content4.getBytes()); fos4.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取道具数 private String readFiles5() { String content5 = null ; try { FileInputStream fis = openFileInput(FILENAME5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content5 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content5; } // 保存文件内容 private void writeFiles5(String content5) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos5 = openFileOutput(FILENAME5, Context.MODE_PRIVATE); fos5.write(content5.getBytes()); fos5.close(); } catch (Exception e) { e.printStackTrace(); } } }
商城类:
package com.example.XXSCYS;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import android.R.integer;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class shangcheng extends Activity{ OnClickListener listener1 = null; Button button1;//定义按钮 public static final String FILENAME4 = "money.set"; public static final String FILENAME5 = "daoju.set"; private int money; private int daoju; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.shangcheng); listener1 = new OnClickListener() { public void onClick(View v) { String m; String n; m=readFiles4(); n=readFiles5(); final int i = Integer.parseInt(m); final float j = Float.parseFloat(n); if(i<=0){ AlertDialog.Builder builder = new Builder(shangcheng.this); builder.setTitle("信息提醒" ) ; builder.setMessage("对不起,您的金币不足!!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); } else{ money=i-50; daoju=(int) (j+1); writeFiles4(""+money); writeFiles5(""+daoju); AlertDialog.Builder builder = new Builder(shangcheng.this); builder.setTitle("信息提醒" ) ; builder.setMessage("恭喜您,道具购买成功!" ) ; builder.setPositiveButton("确定" , null ); builder.show(); } } }; setContentView(R.layout.shangcheng); button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(listener1); } // 读取金币 private String readFiles4() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 保存文件内容 private void writeFiles4(String content4) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos4 = openFileOutput(FILENAME4, Context.MODE_PRIVATE); fos4.write(content4.getBytes()); fos4.close(); } catch (Exception e) { e.printStackTrace(); } } // 读取道具数 private String readFiles5() { String content5 = null ; try { FileInputStream fis = openFileInput(FILENAME5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content5 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content5; } // 保存文件内容 private void writeFiles5(String content5) { try { // 打开文件获取输出流,文件不存在则自动创建 FileOutputStream fos5 = openFileOutput(FILENAME5, Context.MODE_PRIVATE); fos5.write(content5.getBytes()); fos5.close(); } catch (Exception e) { e.printStackTrace(); } } }
用户信息类:
package com.example.XXSCYS;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class xinxi extends Activity{ TextView textView; public static final String FILENAME3 = "dengji.set"; public static final String FILENAME4 = "money.set"; public static final String FILENAME2 = "xinxi.set"; public static final String FILENAME5 = "daoju.set"; private String money; private String dengji; private String nicheng; private String daoju; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.xinxi); nicheng=readFiles2(); money=readFiles4(); dengji=readFiles3(); daoju=readFiles5(); textView = (TextView) findViewById(R.id.textView1); textView.setText("昵称:"+nicheng+"\n"+"等级:"+dengji+"\n"+"金币:"+money+"\n"+"道具:" +daoju+"\n\n"+"温馨提示:"+"\n"+"每答对一道题可获取10金币,等级提升0.1级,答错一题则扣5金币"); } // 读取昵称 private String readFiles2() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME2); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 读取等级 private String readFiles3() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME3); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 读取金币 private String readFiles4() { String content4 = null ; try { FileInputStream fis = openFileInput(FILENAME4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content4 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content4; } // 读取道具数 private String readFiles5() { String content5 = null ; try { FileInputStream fis = openFileInput(FILENAME5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) != -1) { baos.write(buffer, 0, len); } content5 = baos.toString(); fis.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } return content5; } }
附加类:
package com.example.XXSCYS;import android.app.Activity;import android.os.Bundle;public class a extends Activity{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.a); }}
项目发布:
我们团队把整个项目文件上传到Github,链接地址:
app推广:
第一步:在QQ群和微信群里边,呼吁大家下载APP体验,但是效果比较差,下载量比较小,于是采用逐个逐个单独和同学沟通,认真听取他们的体验感受。
第二步:我们采用了人海战术,通过微信公众号来推广,找到一些微信公众号平台,比如:广商微生活。在底部菜单加上我们APP的下载链接,引导他们下载使用。
第三步:最后采用有针对性的推广,锁定用户人群,小学生的家长,于是找到各个同学的亲戚朋友,让他们下载APP体验,总结不足和优点。
总结:这推广过程中,我们也遇到了很多困难,但是,我们收获了很多,明白产品推广的不易之处,相信这份体验会给将来的学习和工作带来一点帮助。