我的回答总是显示为零?

问题描述:

我正在做果冻豆猜测。我的老师给我们提供了一个长度为1.93厘米,直径为1.39厘米,瓶子体积为500的基本案例。答案应该是180.我的代码没有出现任何错误,但我的答案为零时应该为零是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"); 
      } 
     }); 

    } 
} 

Jellybeanspace从未分配。所以它的0. THAT使volumeOfBeans 0.

+0

也jellybeanfat –

+0

也jellybeantall – pandamakes