count() 1. int return type. 2. Two double parameters and one int parameter named
ID: 3784133 • Letter: C
Question
count()
1. int return type.
2. Two double parameters and one int parameter named respectively a, b, and mL. (mL represents milliliters)
3. Returns an estimate of the number jelly beans in a jar with volume mL where a jelly bean has length a and height b (in cm).
4. The volume of a jelly bean is estimated to be
5 · · a · b2 / 24
5. Assume the jelly bean loading capacity of a jar is 69.8%.
6. The number of jelly beans would be
v · c / j
where v is the volume of the jar, c is the loading capacity, and j is the estimate size of a jelly bean
Need java code written written following these guidelines. Thank you.
Explanation / Answer
/** * @fileName :CountJellyBean.java * @author * @since 28-01-2017 **/ public class CountJellyBean { /** * * @param a width of jelly beans * @param b height of jelly beans * @param ml volume of jar * @return number of jelly beans */ public static int count(double a, double b, int ml) { double j = (Math.PI * a * b * b) / 24; return (int) ((ml * 69.8) / (100 * j)); } public static void main(String[] args) { System.out.println(count(2,3,10)); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.