Pair programming: The Golden Dot game

Source: Internet
Author: User

Golden point game is a very simple game, in the C language environment using arrays and for loop can be done. But on the premise of providing the input interface, my partner Pan and I boldly decided to use Java after a brief discussion.

Since we have not studied Java before, so this programming encountered a lot of problems, although in the library borrowed Java books, but still have a small difficulty, for the sake of insurance we first draw a flowchart to ensure the realization of basic functions. The main body of the program we used three arrays, two-dimensional array numn[][] to store the number of games, of course, this number is manual input. In the array goal[], the absolute value of the difference between the number in the game and the G is set, that is, the number of inputs per game is: x1,x2,x3,......, xn,goal[i]=|xi-(X1+X2+X3+......+XN)/n*0.618| (1<=i<=n). Goal[i] and Gan[i] in the scoring array gan[] are scored by comparing the size of the number in the goal[] array to the maximum of [] and minimum goal[j]. With a For loop, and after the input and output is added, the game is printed once per round, which is the output array gan[].

Importjava.awt.event.MouseEvent;ImportJava.util.Scanner; Public classShiyan4 {@SuppressWarnings ("Resource") Public Static voidMain (String args[]) {Scanner in=NewScanner (system.in);//defining an object using the Scanner class        DoubleNumn[][] =New Double[100] [100]; DoubleGoal[] =New Double[100]; DoubleGan[] =New Double[100]; Doublemax=0,min=100; DoubleSum=0,g=0; System.out.println ("Please enter the number of people mump"); DoubleNump=in.nextdouble ();//receive float type dataSystem.out.println ("Please enter the number of games MUMG"); DoubleNumg=in.nextdouble ();//receive float type number         for(inth=0;h<nump;h++) {Goal[h]=0; GAN[H]=0; }         for(ints=0;s<numg;s++) {System.out.println ("Game Start");  for(intk=0;k<nump;k++) {System.out.println ("Number of values calculated by player input num value is shaped"); Doublenum = in.nextdouble ();//receive float type dataNumn[s][k]=num; }                                            for(intj=0;j<nump;j++) {sum+=Numn[s][j]; } G= (sum/nump) *0.618;//Ask G value      DoubleDif=0;  for(intqq=0;qq<nump;qq++) {//Ask for fractionsdif=math.abs (numn[s][qq]-G); GOAL[QQ]=dif; }         for(intf=0;f<nump;f++)         {            if(max<goal[f]) Max=Goal[f]; if(min>goal[f]) min=Goal[f]; }          for(intth=0;th<nump;th++)         {          if(goal[th]==min) gan[th]=gan[th]+Nump; if(goal[th]==max) gan[th]=gan[th]-2; }                               for(inttt=0;tt<nump;tt++) {System.out.println (Gan[tt]); }        }        }}

The above code implements the programming goal, but because we all are first contact Java, therefore did not realize the interface optimization, therefore actually said we did not realize the question request, even the programming also has the flaw, is not standard. As far as Java is concerned, this is the maximum we can do now, and we will continue to work hard.

This project my partner is Pan, he is a very challenging spirit of the people, using Java to do the project is also his proposed, while he likes to do the work and then solve the problem to find solutions, learning ability is very strong. This project in the learning process I found myself a lot of shortcomings, but also from my partner learned a lot.

Program code has been uploaded to Coding:project-2

Pair programming: The Golden Dot game

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.