我的回答总是显示为零?

时间:2017-02-11 08:03:08

标签: android android-studio

我正在做一个果冻豆猜测器。我的老师给了我们一个基本案例,长度为1.93厘米,直径为1.39厘米,罐子大小为500.答案应该是180.我的代码没有任何错误,但我的答案应该为0是180.请帮忙!

public class MainActivity extends AppCompatActivity {
    EditText jellyBeanLength, jellyBeanDiameter, jarSizeVolume;
    double jellybeantall, jellybeanfat, jellybeanspace, volumeOfOneJellyBean, volumeofBeans;
    final double loadFactor = .702; //worked for class jelly bean. Got the same answer on board if jar size was 500, length was 1.93 and diameter was 1.39.
    TextView answer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        jellyBeanLength = (EditText) findViewById(R.id.length);
        jellyBeanDiameter = (EditText) findViewById(R.id.diameter);
        jarSizeVolume = (EditText) findViewById(R.id.jarsize);
        answer = (TextView) findViewById(R.id.answer);
        Button solveButton = (Button) findViewById(R.id.calculate);


        solveButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                volumeOfOneJellyBean = (3.14159265359 / 6) * (jellybeanfat * jellybeanfat) * (jellybeantall);
                volumeofBeans = (jellybeanspace * loadFactor) / volumeOfOneJellyBean;
                int jellyGuess = (int) (volumeofBeans);
                answer.setText("My guess is " + jellyGuess + " Jelly Beans");
            }
        });

    }
}

1 个答案:

答案 0 :(得分:0)

永远不会分配Jellybeanspace。所以它的0.这使得volumeOfBeans为0。