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");
}
});
}
}
答案 0 :(得分:0)
永远不会分配Jellybeanspace。所以它的0.这使得volumeOfBeans为0。