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

Java1 Im running on a time crunch and need some help. Can anyone help me with co

ID: 3858392 • Letter: J

Question

Java1

Im running on a time crunch and need some help. Can anyone help me with code that will do the following.

There will be two files for this problem. The first one, called TestLarger will hold the main method. The second file called NumberUtil will hold the method that will determine the larger of two numbers.

The name of the method that will return the larger of the two numbers, will be called largerNumber.

Create the necessary variables. The two numbers sent to the largerNumber method will be doubles.

Within the largerNumber method, compare the two numbers to see which is larger and return that number.

From the main method, prompt the user to enter two numbers (doubles). Those will be the two numbers sent to the largerNumber method.

* Within the main method, call the largerNumber method and pass the two input numbers to it.

From the main method use appropriate labels and display the two input numbers and designate which one is the larger.

Explanation / Answer

NumberUtil.java

public class NumberUtil {

public static double largerNumber(double a, double b) {

if (a > b) {

return a;

} else {

return b;

}

}

}

TestLarger.java

import java.util.Scanner;

public class TestLarger {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter the first value: ");

double a = scan.nextDouble();

System.out.print("Enter the second value: ");

double b = scan.nextDouble();

double large = NumberUtil.largerNumber(a, b);

System.out.println("Large value is "+large);

}

}

Output:

Enter the first value: 5.5
Enter the second value: 6.6
Large value is 6.6

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote