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

Grading criteria:Writing overloaded methods to do difference tasks.Using Scanner

ID: 3921799 • Letter: G

Question

Grading criteria:Writing overloaded methods to do difference tasks.Using Scanner classUsing loopsUsing CastingUsing ReturnUsing the Math classAssignment:

This assignment will consist of three methods in addition to the main method.Class name is: RootsMethod names are: roots


Main method
A. Will use a Scanner object to prompt for a single integer value.B. Will call the “roots” method with the single int value provided by the Scanner.

First method (roots)
A. Has one formal int parameter. The parameter indicates how many times to execute the

internal loop of the method. The return type is void.B. Will use a Scanner object to input two int values when prompted. a. Input and prompt are to be Inside of the loop.C. Will print your name on one lineD. Will call the second “roots” method from inside the print statement that printed yourname. E. Pass the second “roots” method the two int values input from the Scanner object.F. Print the result of the call to the second method on the next line. G. These two lines will be printed for each iteration of the loop.

Second method (roots)
A. Has two formal int parameters. The return type is double.B. Will cast the two int parameters as doubles and pass to the third “roots” method. C. The return value will be printed without a carriage return/ line feedD. Will compute and return the square root of the sum of the squares of the two int

parameters.


Third method (roots)
A. Has two double parameters. The return type is double.
B. Will compute and return the quotient of the cube of the first parameter divided by the

second. That is: (first^3)/second

Explanation / Answer

import java.util.Scanner;

public class RootsMethod {
   /**
   * @param args
   */
   public static void main(String[] args) {
       Scanner scanner = null;
       try {
           scanner = new Scanner(System.in);
           System.out.print("Enter the Integer : ");
           int value = scanner.nextInt();
           new RootsMethod().roots(value);
       } catch (Exception e) {
           // TODO: handle exception
       }

   }

   /**
   * @param value
   */
   public void roots(int value) {

       Scanner scanner = null;
       try {
           scanner = new Scanner(System.in);
           for (int i = 0; i < value; i++) {

               System.out.print("Enter the Integer 1 : ");
               int value1 = scanner.nextInt();

               System.out.print("Enter the Integer 2 : ");
               int value2 = scanner.nextInt();

               System.out.println("Name :");
               System.out.println("square root of the sum of the squares: "
                       + roots(value1, value2));

           }

       } catch (Exception e) {
           // TODO: handle exception
       }

   }

   /**
   * @param value1
   * @param value2
   */
   public double roots(int value1, int value2) {

       System.out.println("" + roots((double) value1, (double) value2));
       return Math.sqrt((value1 * value1) + (value2 * value2));

   }

   /**
   * @param value3
   * @param value4
   * @return
   */
   public double roots(double value3, double value4) {

       return (value3 * value3 * value3) / value4;
   }

}
OUTPUT:
Enter the Integer : 3
Enter the Integer 1 : 1
Enter the Integer 2 : 2
Name :
0.5
square root of the sum of the squares: 2.23606797749979
Enter the Integer 1 : 4
Enter the Integer 2 : 5
Name :
12.8
square root of the sum of the squares: 6.4031242374328485
Enter the Integer 1 : 6
Enter the Integer 2 : 7
Name :
30.857142857142858
square root of the sum of the squares: 9.219544457292887