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

I\'m am recieving this error in my java code: GrammarProcessor.java:17: error: \

ID: 662750 • Letter: I

Question

I'm am recieving this error in my java code:

GrammarProcessor.java:17: error: '.class' expected
while(int i = 0; i < rulesList.size(); i++){

Here's my code. I hope you have help me find my mistake!!

9 public class GrammarProcessor 10 //Variables 11 private Map rules new TreeMap; //Use a ruleName to find the grammatical rule 12 ublic GrammarProcessor List grammar) [ 13 14 15 16 17 18 19 20 21 List rules1st = new ArrayList(); rules1st = (List) grammar; //Type cast to try insure proper type while (inti 0; i

Explanation / Answer

Answer:

List of Errors and Corrections:

Error 1: line 16

Syntax of the while loop is an error. A while loop contains one or more conditions. If more conditions are to be performed then by using the boolean operators like and(&&), or(||), not(!=), <, <=, >, >=, <> such type of symbols are used.

Example:

while(a > b && a > c)

{...}

The syntax of the while loop provided in the code is in-correct. The actual syntax that is provided is used for "for- loop".

The syntax of "for-loop" is

            for(initialise the variable; condition; incrementation).

Example:

           for(int i=0; i< ruleList.size(); i++)

           {...}

So, change the line #16 to for loop as

     for(int i=0; i<rulesList.size(); i++)

Error 2: Line 19

While using the split and trim methods, the operations are performed from right to left.

So, the error is split method cannot be followed by trim method.

Correction: A trim function can be followed by a split function.

Therefore, change line #19 as

            String[] right=token[1].trim().split("[|]");

Error 3: Line 33

In Map class, there is no method called keyset(). This is an error.

The method that is present in Map class is keySet(). This is correct syntax.

Since, Java is a case sensitive language. Need to be careful while using or calling the methods and the variables.

Therefore, change line #33 as,

            return rules.keySet().toString();

Error 4: Line 43

Error is

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