File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java programming contest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java programming contest" Watch "Java programming contest" New topic
Author

Java programming contest

Jigar Gandhi
Greenhorn

Joined: May 13, 2008
Posts: 20
We are conducting a java programming competition and we are going to eliminate the participants on the basis of number of lines of code.
But we have a problem how to count the number of lines.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8996
    
    9

If you are serious, I think you are barking up the wrong tree because lines of code are not an indication of correctness or quality of code (unless, of course, short/long code is the purpose of the exercise).
In any case, how about showing some effort? Do you know how to read files? Keep a counter? What exactly don't you need help with?


[How To Ask Questions On JavaRanch]
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
What you might want to do is create a program similar to a tokenizer/syntax analyzer that:

0) Given an input file (the program you are counting)
1) eliminate comments
2) count constructs like method declarations, blocks like for-loop, semicolons that terminates statements (e.g. those inside for loop are not counted)

You would therefore need to learn all constructs allowed in your competition, e.g. inner classes.
Jigar Gandhi
Greenhorn

Joined: May 13, 2008
Posts: 20
Thank you for the reply it helped but my friend Joe Ess says that the quality of the program does not depend upon the lines of code. then being a student and conducting competition for students then tell me the unbiased method to judge a code( actually we can judge but we do not want to get in argument with the participants who are hungry for the prize).
Is there any standard method.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
Originally posted by JIGAR GANDHI:
Thank you for the reply it helped but my friend Joe Ess says that the quality of the program does not depend upon the lines of code. then being a student and conducting competition for students then tell me the unbiased method to judge a code( actually we can judge but we do not want to get in argument with the participants who are hungry for the prize).
Is there any standard method.


Yes, there are good ones you can do.

Here's one.

Require the solution to be in a format, such that, you can automatically test his solution by passing it to you test program.

If all of them have correct solutions, then you can base it on who finished first.

You can also specify which java statements, classes, etc. are allowed.

For example, the solution must 'implement' an 'interface' that you provided.

You simply create a test program that tests his solution, as you know the interface. Test it on all scenarios to see that his solution is correct.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42913
    
  68
Just in case you're curious anyway about the NCSS (non-commenting source statements) of a piece of code -which is really what you want to count, not LOC-, look for the JavaNCSS library.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8996
    
    9

The ACM sponsors programming contests for college students. You could look at their rules and problem sets and see if they are a good match. They use a setup similar to what Jesus proposes and the winner is the team that solves the most problems in the given time (ties are broken by times).
Jigar Gandhi
Greenhorn

Joined: May 13, 2008
Posts: 20
The method of counting lines through JavaNCSS library is a bit complicated you people being infallible software programmers since ages may be doing something more easier to count the number of lines in your project. Can I know what you people do to count the non commenting source statements. If using a tool can i get to access the tool or is their any easy way to count the lines by any java API classes .
please help!!
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
The advice given to you above, from different members, already constitute the simplest, most efficient, and realistic clues on how you can proceed on your problem.
Suraj Chandran
Ranch Hand

Joined: May 20, 2008
Posts: 53
I think you really shouldn't conduct the exam.


I guess there are couple of design issues in this classic software the GOD coded.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

I think you really shouldn't wake the zombies.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java programming contest