|
-
Cyclomatic complexity
Hi I have been given an asignment to read a file and determine the cyclomatic complexity I have tried a few variations but cant seem to get the program to count the 'if','while' etc it always gives 1 as result
does anyone know how to do this
I would really appreciate any help below is 1 of the codes I have tried
import java.io.*;
import java.util.*;
public class complexity {
static BufferedReader keyboard=new
BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
public static void main(String[] args) throws IOException {
String[] keywords = {"if","while","switch","for"};
int complexity = 1;
String fileName;
screen.println();
screen.println("Enter the Java file to be read: ");
fileName = new String(keyboard.readLine());
FileInputStream fs = new FileInputStream(fileName);
InputStreamReader r = new InputStreamReader(fs);
StreamTokenizer parser = new StreamTokenizer(r);
while ( parser.nextToken() != StreamTokenizer.TT_EOF )
{
if ( parser.ttype == StreamTokenizer.TT_WORD)
{
for(int i=0; i<keywords.length; i++)
{
if ((parser.sval).equals(keywords))
{
complexity ++;
}
}
}
}
screen.println("complexity = : "+complexity);
}
}
best wishes charliebhoy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks