Primary arithmetic app The first sprint phase of the third day

Source: Internet
Author: User

Team members: Chen Shuyun, Yang Jiane, Chen Xi

Team selection: Primary arithmetic App

First Sprint stage time: 11.17~11.27

This release is on the basis of solving yesterday's problem with team members, add several interfaces, add some functions, modify and add the code as follows:

Modified code:

Package Com.example.calculator;import Java.util.*;import Android.os.bundle;import android.app.actionbar;import Android.app.activity;import Android.content.intent;import Android.view.menu;import Android.view.MenuItem;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;import Android.widget.textview;import Android.widget.toast;import android.content.Intent; public class Calculatoractivity extends Activity {private final random num1=new random ();p rivate final random num2=new Ran Dom ();p rivate final Random r = new Random ();p rivate int x1;private int x2;private int x3;private TextView Text1,text2,text 3;private EditText answer;private button surebutton;//OK buttons private char[] ch={' + ', '-', ' * ', '/'}; Character array private int index = R.nextint (ch.length); Random number, less than the length of the array, 0~3private char d=ch[index]; @Overrideprotected void OnCreate (Bundle savedinstancestate) {ActionBar Actionbar=getactionbar (); actionbar.setdisplayshowhomeenabled (true);Actionbar.setdisplayhomeasupenabled (True); Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_ Calculator); text1= (TextView) Findviewbyid (R.ID.TEXTVIEW1);//random number text3= (TextView) Findviewbyid (R.ID.TEXTVIEW3);// Random number text2= (TextView) Findviewbyid (R.ID.TEXTVIEW2);//random Operation symbol answer= (EditText) Findviewbyid (R.ID.EDITTEXT1); final String a=string.valueof (Num1.nextint); x1=integer.valueof (a); final String b=string.valueof (num2.nextint (100)) ; x2=integer.valueof (b); final String e=string.valueof (d); Text1.settext (a); Text3.settext (b); Text2.settext (e); surebutton= (Button) Findviewbyid (R.id.button);//OK button Surebutton.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View arg0) {//TODO auto-generated method stubfinal String c=answer.gettext (). toString (); x3= Integer.valueof (c); if (index==0) {if (x3==x1+x2) {Toast.maketext (calculatoractivity.this, "correct" +c, Toast.length_short ). Show ();} if (! ( X3==X1+X2) {Toast.maketext (calculatoractivity.this, "error" +c, Toast.length_short). Show ();}} if (index==1) {if (x3==x1-x2) {Toast.maketext (calculatoractivity.this, "correct" +c, Toast.length_short). Show (); if (! ( X3==X1-X2) {Toast.maketext (calculatoractivity.this, "error" +c, Toast.length_short). Show ();}} if (index==2) {if (x3==x1*x2) {Toast.maketext (calculatoractivity.this, "correct" +c, Toast.length_short). Show (); if (! ( X3==X1*X2) {Toast.maketext (calculatoractivity.this, "error" +c, Toast.length_short). Show ();}} if (index==3) {if (x3==x1/x2) {Toast.maketext (calculatoractivity.this, "correct" +c, Toast.length_short). Show (); if (! ( X3==X1/X2) {Toast.maketext (calculatoractivity.this, "error" +c, Toast.length_short). Show ();}}});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.calculator, menu); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//TODO auto-generated method Stubswitch (Item.getitemid ( )) {case Android. r.id.home://Create intentintent intent=new Intent (This,typesactivity.class) to start mainactivity;Add additional FLAG to eject Intent.addflags (intent.flag_activity_clear_top) on activity stack that is above mainactivity; StartActivity (intent); break;default:break;} return super.onoptionsitemselected (item);}}

Added code:

Package Com.example.calculator;import Android.os.bundle;import Android.app.actionbar;import android.app.Activity; Import Android.content.intent;import android.view.menu;import android.view.menuitem;import Android.view.View; Import Android.view.view.onclicklistener;import Android.widget.button;public class Typesactivity extends Activity { Private button Btn1;private button btn2; @Overrideprotected void OnCreate (Bundle savedinstancestate) {ActionBar Actionbar=getactionbar (); actionbar.setdisplayshowhomeenabled (true); actionbar.setdisplayhomeasupenabled (true); Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_types); btn1= (Button) Findviewbyid ( R.id.button1); btn2= (Button) Findviewbyid (R.id.button2); Btn1.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubintent intent=new Intent (); Intent.setclass ( Typesactivity.this, Calculatoractivity.class); startactivity (intent); TypesActivity.this.finish ();}}); Btn2.setonclicklistener(New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method stubintent intent=new Inten T (); Intent.setclass (Typesactivity.this, Calculatorsactivity.class); startactivity (intent); TypesActivity.this.finish ();}});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (r.menu.types, menu); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//TODO auto-generated method Stubswitch (Item.getitemid ( )) {case Android. r.id.home://Create intentintent intent=new Intent (This,mainactivity.class) to start mainactivity;//Add extra flag, Eject Intent.addflags (intent.flag_activity_clear_top) in activity stack above mainactivity, startactivity (Intent); Break;default:break;} return super.onoptionsitemselected (item);}}

Added two selection buttons "single-question exercise" and "multi-choice exercise";

The layout interface for the multi-choice exercise:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" Android: background= "@drawable/animal" tools:context= ". Calculatorsactivity "> <tablelayout android:layout_width=" fill_parent "android:layout_height=" Fill_parent "&G    T <tablerow android:id= "@+id/tablerow1" android:layout_width= "Wrap_content" android:layout_height= "W Rap_content "> <textview android:id=" @+id/textview1 "android:layout_width=" wrap_content "Android:layout_height=" wrap_content "android:text=" number of input digits "/> <edittext Android Oid:id= "@+id/edittext1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"    android:ems= "5" android:inputtype= "number" > <requestfocus/> </EditText> </TableRow> <tablerow android:id= "@+id/tablerow2" android:layout_width= "Wrap_content" an droid:layout_height= "Wrap_content" > <textview android:id= "@+id/textview2" Android:layo Ut_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "number of input questions"/> <ed Ittext android:id= "@+id/edittext2" android:layout_width= "Wrap_content" Android:layout_hei ght= "Wrap_content" android:ems= "5" android:inputtype= "number"/> </TableRow> <tab Lerow android:id= "@+id/tablerow3" android:layout_width= "wrap_content" android:layout_height= "Wrap_con Tent "> <teXtview android:id= "@+id/textview3" android:layout_width= "Wrap_content" Android:layout_hei            ght= "wrap_content" android:text= "Input Time"/> <edittext android:id= "@+id/edittext3"            Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:ems= "3" android:inputtype= "number"/> <textview android:id= "@+id/textview4" android:layout _width= "Wrap_content" android:layout_height= "wrap_content" android:text= "min"/> <edittex T android:id= "@+id/edittext4" android:layout_width= "Wrap_content" android:layout_height= " Wrap_content "android:ems=" 3 "android:inputtype=" number "/> <textview androi            D:id= "@+id/textview5" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Seconds"/> </TableRow> <tablerow android:id= "@+id/tablerow4" android:layout_width= "Wrap_content"        android:layout_height= "Wrap_content" android:layout_margintop= "10DP" > <radiogroup        Android:id= "@+id/group" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" > <radiobutton android:id= "@+id/radio0" android:layout_width= "Wrap_content" Andro id:layout_height= "Wrap_content" android:checked= "true" android:text= "@string/add"/> <r Adiobutton android:id= "@+id/radio2" android:layout_width= "Wrap_content" android:layout_he            ight= "Wrap_content" android:layout_alignleft= "@+id/radio0" android:layout_below= "@+id/radio0" android:text= "@string/jian"/> <radiobutton android:id= "@+id/radio1" android:layou  T_width= "Wrap_content"          android:layout_height= "Wrap_content" android:text= "@string/cheng"/> <radiobutton Android:id= "@+id/radio3" android:layout_width= "wrap_content" android:layout_height= "Wrap_conten T "android:text=" @string/chu "/> </RadioGroup> </TableRow> <tablerow android: Id= "@+id/tablerow5" android:layout_width= "wrap_content" android:layout_height= "wrap_content" > </Ta blerow> <button android:id= "@+id/button1" android:layout_width= "Wrap_content" android:layout _height= "Wrap_content" android:text= "Start"/></tablelayout> </RelativeLayout>

Demo App run Screen:

1) Main interface:

2) Select the interface:

3) Single question exercise: (Resolve success)

4) Multiple Choice exercises:

The next task is to continue to improve the "multi-choice Exercise" Interface! Come on!

Primary arithmetic app The first sprint phase of the third day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.