Android Open Source - ddgatve-android Questions






From Project

Back to project page ddgatve-android.

License

The source code is released under:

Apache License

If you think the Android project ddgatve-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package lv.ddgatve.games.mtable;
/*www.jav a2s .  c o  m*/
import java.util.Random;

public class Questions {

  private int max;
  private int first;
  private int second;
  Random r = new Random();
  private int type; // 1 - addition; 2 - subtraction; 3 - multiplication; 4-
            // division

  public Questions(int max) {
    this.max = max;
    next();
  }

  public void next() {
    int temp = r.nextInt(10);
    if (temp < 1 || temp > 4) {
      type = 3;
    } else {
      type = temp;
    }
    if (type == 3) {
      first = r.nextInt(19) + 2;
      int maxSecond = (int) Math.floor((double) max / first);
      second = r.nextInt(maxSecond - 1) + 2;
    } else if (type == 1) {
      first = r.nextInt(max + 1);
      int maxSecond = max - first;
      second = r.nextInt(maxSecond + 1);
    } else if (type == 2) {
      first = r.nextInt(max + 1);
      int maxSecond = first;
      second = r.nextInt(maxSecond + 1);
    } else if (type == 4) {
      second = r.nextInt(19) + 2;
      int maxSecond = (int) Math.floor((double) max / second);
      int answer = r.nextInt(maxSecond - 1) + 2;
      first = answer * second;
    }
  }

  public String getQuestion() {
    String[] operators = new String[] { "*", "+", "-", "*", "/" };
    if (type >= 1 && type <= 4) {
      return "" + first + operators[type] + second;
    } else {
      return "0*0";
    }
  }

  public int getType() {
    return type;
  }

  public int getAnswer() {
    if (type == 1) {
      return first + second;
    } else if (type == 2) {
      return first - second;
    } else if (type == 3) {
      return first * second;
    } else if (type == 4) {
      return first / second;
    } else {
      return 0;
    }
  }
  
  

  // public static void main(String[] args) {
  // Questions q = new Questions(100);
  // for (int i = 0; i < 100; i++) {
  // System.out.println(q.nextQuestion() + " = " + q.getAnswer());
  // }
  // }

}




Java Source Code List

lv.ddgatve.applets.ColoredCircleApplet.java
lv.ddgatve.applets.MovingCircleApplet.java
lv.ddgatve.applets.PlainCircleApplet.java
lv.ddgatve.applets.SmoothCircleApplet.java
lv.ddgatve.games.game15.Game15Activity.java
lv.ddgatve.games.game15.Game15Frame.java
lv.ddgatve.games.game15.ImageAdapter.java
lv.ddgatve.games.game15.PickFrameDialogFragment.java
lv.ddgatve.games.game15.SummaryActivity.java
lv.ddgatve.games.main.MainActivity.java
lv.ddgatve.games.mtable.DataHolder.java
lv.ddgatve.games.mtable.DisplayMessageActivity.java
lv.ddgatve.games.mtable.MainActivity.java
lv.ddgatve.games.mtable.Questions.java
lv.ddgatve.games.mtable.SummaryActivity.java
lv.ddgatve.math.main.ExampleActivity.java
lv.ddgatve.math.main.MainActivity.java
lv.ddgatve.math.main.PostAsyncTask.java
lv.ddgatve.math.main.RegisterActivity.java
lv.hello.HelloWorld.java
lv.hello.MultiplicationTable.java
lv.kapsitis.myfirstapp.MainActivity.java