Complete the following program by writing in the methods. Make sure that the cod
ID: 3594896 • Letter: C
Question
Complete the following program by writing in the methods. Make sure that the code matches the sample run and make sure not to hardcode any part of the sample run since we will be using other examples as well. DO NOT MODIFY THE MAIN METHOD-only write in the methods (where it says write code here). You will turn in the whole program. import java.util.Scanner; ublic class NumeroDeux public static int getUserNum(String message) //write code here public static String getUserString(int n) //write code here public static boolean checkNumLength(int a, int check1, int check2) //write code here public static void main(Stringl args) //DO NOT MODIFY boolean choice-true; int userln-0 while(choice) userln getUserNum("Enter a number between 4-6:"); choice-checkNumLength(userin, 4, 6) String input-getUserString(userln); choice-true; int userln2-0 while(choice) userln2-getUserNum("Enter another number (for substring) between 1-3:"); choice-checkNumLength(userln2, 1, 3); System.out.println(input.substring(0,userln2)); SAMPLE RUN: Enter a number between 4-6:3 Enter a number between 4-6:8 Enter a number between 4-6:4 Enter a word at of length 4: dogg Enter another number(for substring) between 1-3:3 dogExplanation / Answer
NumeroDeux.java
import java.util.Scanner;
public class NumeroDeux {
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
static Scanner sc = new Scanner(System.in);
private static int getUserNum(String string) {
int num = 0;
System.out.print(string);
num = sc.nextInt();
return num;
}
public static void main(String[] args) {
boolean choice = true;
int userIn = 0;
while (choice) {
userIn = getUserNum("Enter a number between 4-6:");
choice = checkNumLength(userIn, 4, 6);
}
String input = getUserString(userIn);
choice = true;
int userIn2 = 0;
while (choice) {
userIn2 = getUserNum("Enter another number (for substring) between 1-3 :");
choice = checkNumLength(userIn2, 1, 3);
}
System.out.println(input.substring(0, userIn2));
}
private static String getUserString(int userIn) {
String str = null;
while (true) {
System.out.print("Enter a word at of length " + userIn + ":");
str = sc.next();
if (str.length() != userIn) {
continue;
} else {
break;
}
}
return str;
}
private static boolean checkNumLength(int userIn, int check1, int check2) {
if (userIn < check1 || userIn > check2)
return true;
else
return false;
}
}
_________________
Output:
Enter a number between 4-6:3
Enter a number between 4-6:8
Enter a number between 4-6:4
Enter a word at of length 4:dogg
Enter another number (for substring) between 1-3 :3
dog
_____________Could you rate me well.Plz .Thank You