Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Write a method named getCategory, that receives numeric value (double) and

ID: 3784315 • Letter: J

Question

JAVA

Write a method named getCategory, that receives numeric value (double) and returns a String, "Over", if the value is over 100.0, "Average", if the value is less than or equal to 100.0 and greater than 25.0, "Below" if the value is 25.0 or less. Write a main method that inputs a number, calls getCategory with the number, and prints the returned String. Signature of the method is
public static String getCategory(double value)

Run the program. Input 101.0 Run it again, use 25.0. Capture the console output. Run it again, use 14.5. Capture the console output from each run.

Put the program code and console output at the end of your text file

Explanation / Answer

//Tested on Eclipse

/***********************Category.java*********************/

import java.util.Scanner;

public class Category {

   /**
   * @param args
   */
   /**
   * This method takes double value as params and checks for condition if
   * value is greater then 100 then it is Over if value greater then 25 and
   * less then equal 100 then it is Average if value is less then 25 then it
   * is Below
   * */
   public static String getCategory(double value) {
       if (value > 100) {
           return "Over";
       } else if (value > 25 && value <= 100) {
           return "Average";
       } else {
           return "Below";
       }
   }

   public static void main(String[] args) {
       // Scanner class object for input
       Scanner input = new Scanner(System.in);
       // prompt for user input
       System.out.println("Please enter the value");
       double value = input.nextDouble();
       // calling getCategory method
       String result = getCategory(value);
       // printing result
       System.out.println("Category " + result);

   }

}

/****************output***********************/

Please enter the value
101.0
Category Over

Please enter the value
25
Category Below

Please enter the value
14.5
Category Below

Thanks a lot