Hi all
i am doing an assignment, its a pice of code that will work out the complexity of a given java code/file according to Mcabes theory.
Mcabes theory is that the compleity of a programe is determined by the number of "if, while, case, repeates" staments are used +1. and it should ignore any comments that contain these words.
in my code it can ignore single line comments but multilines comment i am having problems with.
this is what i have so far:
/******************/
import java.io.*;
import java.util.*;
public class CC
{
static BufferedReader keyboard = new BufferedReader(new
InputStreamReader(System.in));
//static PrintWriter screen = new PrintWriter(System.out, true);
public CC()throws IOException
{
String fileName;
System.out.println("Enter the file to evaluate >");
//screen.flush();
fileName = new String(keyboard.readLine());
BufferedReader in = new BufferedReader(new FileReader(fileName));
ReadJavaFile(in);
}
public static void ReadJavaFile(BufferedReader in /*javaFile*/) throws IOException
{
int cycloComp = 0;
String aToken;
boolean commentChecker = false;
//String line= javaFile.readLine();
String line = in.readLine();
//while ((line = javaFile.readLine()) != null)
while (line != null)
{
StringTokenizer t = new StringTokenizer(line);
while (t.hasMoreTokens())//line != null
{
aToken = t.nextToken();
if (aToken.equals("//"))
{
line = in.readLine();
}
if (aToken.equals("/*"))
{
aToken = t.nextToken();
line = in.readLine();
}
if (aToken.equals("*/"))
{
line = in.readLine();
}
if (aToken.equals("if") && commentChecker != true)
{
cycloComp++;
}
if (aToken.equals("while"))
{
cycloComp++;
}
if (aToken.equals("for"))
{
cycloComp++;
}
if (aToken.equals("case"))
{
cycloComp++;
}
if (aToken.equals("switch"))
{
cycloComp++;
}
}
line = in.readLine();
}
if(cycloComp >=10)
{
cycloComp=cycloComp+1;
System.out.println("The complexity of this Program is:> "+cycloComp);
System.out.println("**MESSAGE** This Program is too complex according to Mcabe theory");
}
else
{
if(cycloComp ==0)
{
System.out.println("The complexity of this Program is:> "+cycloComp);
}
else
{
cycloComp=cycloComp+1;
System.out.println("The complexity of this Program is:> "+cycloComp);
}
}
}
}
/*************************/
can anyone help please
thank you