Stucked on loops
<p>I'm a just a beginner to android &amp; java. I'm trying to build an app that will tell you if you win or lose base on the Martingale on gambling.</p>

<p>My concept is, you can set your money, target and the minimum bet.</p>

<p>for example is if I set my current money is 1000, and my target is to get 1100, and the minimum bet is 100, the app will auto run the function for example 10 times and calculate the win rate.</p>

<p>now I'm stucked, on how to ask the app calculate the win rate, I tried the code below, but it's not working.</p>

<pre><code>public int winPercentage (){
  int numberWin = 0;
  for (int i = 0; i &lt;= 10; i++) {
    boolean win = calRate(double currentMoney, double theTarget, double minBet);
    if (win) {
      numberWin = numberWin + 1;
    }
  }
  return numberWin;
}
</code></pre>

<p>My Full Java Code Here</p>

<pre><code>package com.example.android.gambling;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  }

  public void seeRate(View view) {

    EditText cMoney = (EditText) findViewById(R.id.money);
    double currentMoney = Double.parseDouble(cMoney.getText().toString());

    EditText target = (EditText) findViewById(R.id.target);
    double theTarget = Double.parseDouble(target.getText().toString());

    EditText bet = (EditText) findViewById(R.id.bet);
    double minBet = Double.parseDouble(bet.getText().toString());

    TextView textview = (TextView)findViewById(R.id.textView);
    textview.setText("You " + winPercentage());
  }

  public boolean calRate(double currentMoney, double theTarget, double minBet) {
    while (currentMoney &gt; minBet) {
      boolean win = winRate();
      if (win) {
        currentMoney += minBet;
        minBet = minBet;
      }
      else {
        currentMoney -= minBet;
        minBet *= 2;
      }
      if (currentMoney &gt;= theTarget){
        return true;
      }

    }

    return false;
  }

  private boolean winRate() {
    double d = Math.random();
    if (d &lt; 0.5)
      return true;
    else
      return false;
  }

  public int winPercentage (){
    int numberWin = 0;
    for (int i = 0; i &lt;= 10; i++) {
      boolean win = calRate(double currentMoney, double theTarget, double minBet);
      if (win){
        numberWin = numberWin + 1;
      }
    }
    return numberWin;
  }
}
</code></pre>

<p><strong>Edit</strong></p>

<p>Now that i amend the code as below, the android studio shows no error, but when i try to emulate it, it can't be opened, keep showing (unfortunately, app has stopped)</p>

<pre><code>package com.example.android.gambling;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    EditText cMoney = (EditText) findViewById(R.id.money);
    double currentMoney = Double.parseDouble(cMoney.getText().toString());

    EditText target = (EditText) findViewById(R.id.target);
    double theTarget = Double.parseDouble(target.getText().toString());

    EditText bet = (EditText) findViewById(R.id.bet);
    double minBet = Double.parseDouble(bet.getText().toString());

    boolean findRate = calRate(currentMoney, theTarget, minBet);


    public void seeRate(View view) {


        TextView textview = (TextView)findViewById(R.id.textView);
        textview.setText("You " + winPercentage());



    }

    public boolean calRate(double currentMoney, double theTarget, double minBet) {

        while (currentMoney&gt;minBet){
            boolean win = winRate();
            if (win){
                currentMoney += minBet;
                minBet = minBet;
            }
            else {
                currentMoney -= minBet;
                minBet *= 2;
            }
            if (currentMoney&gt;=theTarget){
                return true;
            }

        }

        return false;
    }

    private boolean winRate() {
        double d = Math.random();
        if (d &lt; 0.5)
        return true;
        else
            return false;

    }

    public int winPercentage (){
        int numberWin = 0;
        for (int i=0; i&lt;=10; i++){
            boolean win = calRate(currentMoney, theTarget, minBet);
            if (win){
                numberWin = numberWin + 1;
            }

        }
        return numberWin/10*100;
    }
}
</code></pre>