Question: JAVA please. Help correct my code. I will include my code below and I will also include the original purpose for my code. Thank you

JAVA please.

Help correct my code. I will include my code below and I will also include the original purpose for my code. Thank you

I am supposed to write a program that will read input from a file and determine whether or not a string of characters is a slop. The file will be organized as follows. The first line contains an integer N between 1 and 100 indicating how many strings of characters are to be tested. The next N lines each contain a string.

Write three recursive methods that determine whether or not a string is a slop. Here are the function signatures:

bool isSlop(string str);

bool isSlap(string str);

bool isSlip(string str);

You will want to write isSlip first, followed by isSlap, and finally isSlop. Make sure that isSlip and isSlap work flawlessly. Do not proceed to isSlop until you are sure that the other two methods work.

Your program should write its output to the console. The first line of output should read SLOPS OUTPUT. Each of the next N lines of output should consist of either YES or NO depending on whether or not the corresponding input line is a Slop. The last line of output should read: END OF OUTPUT.

Shown below is a sample run. The following input data:

2 AHDFG DFGAH

Should produce the following output:

SLOPS OUTPUT YES NO

My code---- I named the file it needs to read "Text.in"

class Main {

// this will check if the string is slip or not. boolean isSlip(String s, int index) { if(index == s.length()) return false; if(index+1 == s.length() ) { // this is the last character. return s.charAt(index) == 'G'; } // check if the first char is not either D or 'E' if( !(s.charAt(index) == 'D' || s.charAt(index) =='E') ) return false; index++; if( s.charAt(index) != 'F') return false; while(index < s.length() && s.charAt(index) == 'F') { index++; } return isSlip(s,index);

}

boolean isSlap(String s, int index){ if(index == s.length()) return false; if(index+1 == s.length()) { return (s.charAt(index) == 'C'); } if(index+2 == s.length()){ // last two character. return (s.charAt(index) == 'A' && s.charAt(index+1) == 'E'); } // choose a substring from index to excluding last index. String slip = s.substr(index,s.length()-1); boolean temp = isSlip(slip,0) && (s.charAt(s.length()-1) == 'C'); Stirng slap = s.substr(index+1,s.length()-1); temp = temp || (s.charAt(index) == 'B' && isSlap(slap,0) && s.charAt(s.length()-1) == 'C'); return temp;

}

void isSlop(String s){ boolean temp = false; for(int i = 2; i < s.length()-2; i ++){ temp = temp || (isSlap(s.substr(0,i), 0 ) && isSlip(s.substr(index+1),0)); } if(temp){ System.out.println("YES"); } else { System.out.println("NO"); }

} public static void main(String[] args) { Scanner scan = new Scanner(System.in); // you can give here the file name that you want. int N = scan.nextInt(); System.out.println("SLOPS OUTPUT"); for(int i = 0 ; i < N ; i+=1){ Stirng s = scan.next(); isSlop(); } System.out.println("END OF OUTPUT");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!