Current location: Hot Scripts Forums » Programming Languages » Everything Java » Regestered Member

Regestered Member

Reply
  #1 (permalink)  
Old 12-04-04, 09:18 AM
ahmed49 ahmed49 is offline
New Member
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Regestered Member

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-05-04, 01:52 PM
Rob_Darkins Rob_Darkins is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Use a StreamTokenizer to remove all comments from the code, see here for example code: http://javaalmanac.com/egs/java.io/ParseJava.html

Good luck,
Rob D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-07-04, 06:34 AM
ahmed49 ahmed49 is offline
New Member
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jhgkj

rgfdgdsfrdesr tre trtert ret rt erwt we trew
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 01-01-05, 06:14 AM
Rob_Darkins Rob_Darkins is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Excuse me?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to add member to member namagodai Script Requests 0 10-24-04 02:54 AM
Please help looking for a script for member pages! wpcadmin PHP 4 08-12-04 11:41 AM
User Authentication / member pages yalrighty Script Requests 0 02-12-04 11:34 PM
member ratings Skeleton Man Hot Scripts Forum Questions, Suggestions and Feedback 7 01-22-04 09:27 PM
new member forcer New Members & Introductions 2 08-03-03 07:19 AM


All times are GMT -5. The time now is 09:12 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.