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

base on Java 1- Write a method which is passed three Strings. The method returns

ID: 3902439 • Letter: B

Question

base on Java

1- Write a method which is passed three Strings. The method returns a 3 if the strings are in alphabetic ascending order (apple, boat, car) , a 2 if the strings are in alphabetic descending order, and a 1 if the strings are in no particular order. You may assume the values of the three strings will all be different?

2- Write a ‘displayMenu()’ method that presents 4 menu options:

option 1 – Get the radius of a circle

option 2 -- Get the area of a circle

option 3 -- Get the circumference of a circle

option 4 -- Quit and returns a value of type int.

Use a do - while loop and insure the user’s input is valid:

Explanation / Answer

Below is your code. I have added a main function to test it. Please let me know if any of my understanding is wrong. I'll help for sure.

Please do rate this answer positive, If i was able to help you. Let me know if you have any issues in comments

public class Chegg123 {

public static int isOrdered(String str1, String str2, String str3) {

if ((str1.compareTo(str2) < 0 && str2.compareTo(str3) < 0)) {

return 3;

} else if ((str1.compareTo(str2) > 0 && str2.compareTo(str3) > 0)) {

return 2;

} else {

return 1;

}

}

public static int displayMenu() {

int choice = 0;

boolean valid = false;

Scanner sc = new Scanner(System.in);

do {

System.out.println("Menu options: ");

System.out.println("1. Get the radius of a circle");

System.out.println("2. Get the area of a circle");

System.out.println("3. Get the circumference of a circle");

System.out.println("4. Quit and returns a value of type int.");

choice = sc.nextInt();

if (choice > 0 && choice < 5) {

valid = true;

} else {

System.out.println("Please enter a valid option.");

}

} while (!valid);

sc.close();

return choice;

}

public static void main(String[] args) {

String str1 = "apple";

String str2 = "boat";

String str3 = "car";

System.out.println("Is ordered (apple, boat, car): " + isOrdered(str1, str2, str3));

System.out.println("Is ordered (car, boat, apple): " + isOrdered(str3, str2, str1));

System.out.println("Is ordered (apple, car, boat): " + isOrdered(str1, str3, str2));

System.out.println(displayMenu());

}

}

Output

Is ordered (apple, boat, car): 3
Is ordered (car, boat, apple): 2
Is ordered (apple, car, boat): 1
Menu options:
1. Get the radius of a circle
2. Get the area of a circle
3. Get the circumference of a circle
4. Quit and returns a value of type int.
6
Please enter a valid option.
Menu options:
1. Get the radius of a circle
2. Get the area of a circle
3. Get the circumference of a circle
4. Quit and returns a value of type int.
5
Please enter a valid option.
Menu options:
1. Get the radius of a circle
2. Get the area of a circle
3. Get the circumference of a circle
4. Quit and returns a value of type int.
0
Please enter a valid option.
Menu options:
1. Get the radius of a circle
2. Get the area of a circle
3. Get the circumference of a circle
4. Quit and returns a value of type int.
-3
Please enter a valid option.
Menu options:
1. Get the radius of a circle
2. Get the area of a circle
3. Get the circumference of a circle
4. Quit and returns a value of type int.
3
3