Use Android to write a small program

Source: Internet
Author: User

Objective:

A small job of the soft worker: realizes "The Golden Partition small game", needs the pair programming, the teammate: Chen Leiun (http://www.cnblogs.com/clyln/), spents two days.

Early thinking Design:

In the form of a key-value pair, map is used as the storage structure. Advantages: The ability to match the data with the user, disadvantage: the implementation of Java is too complex, too much engineering, the need to consume a lot of resources, type conversion error prone.

Later thinking Design:

A two-dimensional array: The first row is used to store the user input raw data, the second row is used to store intermediate data (the absolute value of the first row and G values), and the third row is used to save the user score.

Advantages: Easy to implement and easy to operate

Division: Early: Chen Leiun negative interface design and code inspection interim: Chen Leiun responsible for code inspection, bug check late: Chen Leiun responsible for app testing

I am responsible for the implementation of the algorithm, interface optimization I am responsible for coding and bug correction of my negative interface optimization, code debugging

App Interface Design:

The first version of the Code: implementation of specific functions

 Packagecn.sau.Test;Importjava.util.Arrays;Importjava.util.Collection; Public classTestgolden {Static intNumber = 10;  Public Static voidMain (string[] args) {Double[] Array =New Double[10] [3];  for(inti = 0; i<number;i++)        {             for(intj = 0; j<2;j++)                if(j==0) Array[i][j]=i+10; Else{array[i][2]=0; ARRAY[I][J]= 0; }        }        //Average        DoubleAverage = 0;  for(inti = 0; i<number;i++) {Average= Average +array[i][0]; }        intx =Number ; Average= Average/x; //g value        DoubleG =average *0.618; //Approximate degree         for(inti = 0; i<number;i++) {array[i][1] = Math.Abs (Array[i][0]-average); }                //min: Nearest; Max: Farthest        DoubleMin = array[0][1]; Doublemax = Array[0][1];  for(inti = 1; i<number; i++){            if(Min >array[i][1]) {min=array[i][1]; }            if(max<array[i][1]) {max=array[i][1]; }} System.out.println ("Max:" +max + "\ n min:" +min); //Statistical score         for(inti = 0; i<number;i++){            if(array[i][1]==min) {array[i][2] =Number ; }            Else if(Array[i][1] = =max) {array[i][2]=-2; }        }                         for(inti = 0; i<10;i++) {System.out.print (array[i][2] + "\ n"); }    }    }

Second Edition: porting to the Android platform

 PackageCom.example.m.goldengame10;ImportAndroid.app.AlertDialog;ImportAndroid.content.DialogInterface;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.EditText;ImportAndroid.widget.TextView;/*Golden Segment Games 1.0 version to achieve the following functions: single-machine operation fixed user of 2016/10/16 Finch & Xiaopang*/ Public classMainactivityextendsappcompatactivity {intNumber = 10;//Total number     intCount = 1;//judgment of the number of innings    Double[] Array =New Double[10] [3];    TextView News;    EditText user1;    EditText User2;    EditText User3;    EditText User4;    EditText User5;    EditText User6;    EditText User7;    EditText User8;    EditText User9;    EditText User10;    Button submit;    Button clean; protected voidonCreate (Bundle savedinstancestate) {LOG.V ("Button", "on");  for(inti = 0; i<number;i++) {array[i][0]=0; array[i][1]=0; array[i][2]=0; }        Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); News=(TextView) Findviewbyid (r.id.news); User1=(EditText) Findviewbyid (r.id.user1); User2=(EditText) Findviewbyid (R.ID.USER2); User3=(EditText) Findviewbyid (R.ID.USER3); User4=(EditText) Findviewbyid (R.ID.USER4); User5=(EditText) Findviewbyid (R.ID.USER5); User6=(EditText) Findviewbyid (R.ID.USER6); User7=(EditText) Findviewbyid (R.ID.USER7); User8=(EditText) Findviewbyid (R.id.user8); User9=(EditText) Findviewbyid (R.ID.USER9); User10=(EditText) Findviewbyid (R.ID.USER10); Submit=(Button) Findviewbyid (r.id.submit); Clean=(Button) Findviewbyid (R.id.clean); Submit.setonclicklistener (NewView.onclicklistener () { Public voidOnClick (View v) {News.settext ("+count+" of the "Bureau score"); array[0][0] =double.parsedouble (User1.gettext (). toString ()); array[1][0] =double.parsedouble (User2.gettext (). toString ()); array[2][0] =double.parsedouble (User3.gettext (). toString ()); array[3][0] =double.parsedouble (User4.gettext (). toString ()); array[4][0] =double.parsedouble (User5.gettext (). toString ()); array[5][0] =double.parsedouble (User6.gettext (). toString ()); array[6][0] =double.parsedouble (User7.gettext (). toString ()); array[7][0] =double.parsedouble (User8.gettext (). toString ()); array[8][0] =double.parsedouble (User9.gettext (). toString ()); array[9][0] =double.parsedouble (User10.gettext (). toString ()); //Average                DoubleAverage = 0;  for(inti = 0; i<number;i++) {Average= Average +array[i][0]; }                intx =Number ; Average= Average/x; //g value                DoubleG =average *0.698; //Approximate degree                 for(inti = 0; i<number;i++) {array[i][1] = Math.Abs (Array[i][0]-G); }                //min: Nearest; Max: Farthest                DoubleMin = array[0][1]; Doublemax = Array[0][1];  for(inti = 1; i<number; i++){                    if(Min >array[i][1]) {min=array[i][1]; }                    if(max<array[i][1]) {max=array[i][1]; }                }                //Statistical score                 for(inti = 0; i<number;i++){                    if(array[i][1]==min) {array[i][2] =array[i][2] +Number ; }                    Else if(Array[i][1] = =max) {array[i][2]=array[i][2]-2; }} user1.settext (String.valueof (array[0][2])); User2.settext (string.valueof (array[The])); User3.settext (string.valueof (array[2][2])); User4.settext (string.valueof (array[3][2])); User5.settext (string.valueof (array[4][2])); User6.settext (string.valueof (array[5][2])); User7.settext (string.valueof (array[6][2])); User8.settext (string.valueof (array[7][2])); User9.settext (string.valueof (array[8][2])); User10.settext (string.valueof (array[9][2])); Count++;//for each submission, the number of bureaux plus one            }        }); Clean.setonclicklistener (NewView.onclicklistener () { Public voidOnClick (View v) {//Initialize                for(intI= 0;i<number;i++) {array[i][0]=0; array[i][1]=0; News.settext ("To start the" +count+ "Bureau, please enter the value"); News.settextsize (30); }                //Automatically erase dataUser1.gettext (). Clear ();                User2.gettext (). Clear ();                User2.gettext (). Clear ();                User3.gettext (). Clear ();                User4.gettext (). Clear ();                User5.gettext (). Clear ();                User6.gettext (). Clear ();                User7.gettext (). Clear ();                User8.gettext (). Clear ();                User9.gettext (). Clear ();            User10.gettext (). Clear ();    }        }); }}

App Interface Design:

App Test:

Initial interface first inning input data first inning score Start of the second inning

Code Test Atlas:

App Test other Atlas:

Attached: Android Studio project code: Https://git.coding.net/fench/GodlenGame-on-android.git AppA (Welcome demo): https://git.coding.net/ Fench/godlengame-on-android.git-"golderngameapk

Use Android to write a small program

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.