Question: public class Utilities { /* * Requirements: * - It is strictly forbidden for you to use: * + Any Java library method (e.g., Arrays.sort)
public class Utilities { /* * Requirements: * - It is strictly forbidden for you to use: * + Any Java library method (e.g., Arrays.sort) * (That is, there must not be an import statement in the beginning of this class.) * + arrays * - You will receive an immediate zero for this task if the requirement is violated. * * Only write lines of code within the methods given to you. * Do not add any new helper methods. * Do not declare any variables OUTSIDE the given methods. * You can only declare local variables within each method. * * Your submission will only be graded against: * - JUnit tests given to you in TestUtilities * - additional JUnit tests * (therefore it is important that you test your own methods * by either the console application class App or your own JUnit tests) */
/* Task 1. * * Input Parameters: * - `unitOfWeight` : either "pound" or "kilogram" * - `valueOfWeight` : the weight value * - `unitOfHeight` : either "foot" or "inch" * - `valueOfHeight` : the height value * * Error conditions (in order of priority): * 1. When the `unitOfWeight` is neither "pound" nor "kilogram" (case sensitive). * 2. When the `unitOfHeight` is neither "foot" nor "inch" (case sensitive). * 3. When not both weight value and height value are positive. * If multiple error conditions hold, return a message related to the error with the highest priority. * e.g., invoking getBMIReport("Pounds", -154.3, "Inches", -66.92) has all inputs invalid, * but only an error message about weight unit is returned. * * What to return? * - Return an error message if there is any error. * - Otherwise, calculate the Body Mass Index (BMI) by: weight (in kilogram) divided by the square of height (in meters). * + Use the following conversion rates (when needed): * 1 inch is 0.0254 meter (use it when `unitOfHeight` is "inch") * 1 foot is 0.3048 meter * 1 pound is 0.453592 kilogram * + The calculation result must be formatted with 2 digits after the decimal: * Use String.format("%.2f", someNumber) * + Also, include an interpretation message (case sensitive) according to the following scheme: * BMI < 18.5 means "Underweight" * 18.5 <= BMI < 25.0 means "Normal" * 25.0 <= BMI < 30.0 means "Overweight" * 30.0 <= BMI means "Obese" * * See the JUnit tests related to this method for the precise format of the string return value. */ public static String getBMIReport(String unitOfWeight, double valueOfWeight, String unitOfHeight, double valueOfHeight) { String result = ""; /* Your task is to implement this method, * so that running TestUtilities.java will pass all JUnit tests. * * Recall from Week 1's tutorial videos: * 1. No System.out.println statements should appear here. * Instead, an explicit, final `return` statement is placed for you. * 2. No Scanner operations should appear here (e.g., input.nextInt()). * Instead, refer to the input parameters of this method. * 3. Do not re-assign any of the parameter/input variables. */ // Your implementation of this method starts here. // Do not modify this return statement. return result; }
Examples of output
BMI is: 28.63 (Overweight)
BMI is: 31.69 (Obese)
Error: Pounds is not a valid weight unit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
