1
我正在做果凍豆猜測。我的老師給我們提供了一個長度爲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");
}
});
}
}
也jellybeanfat –
也jellybeantall – pandamakes