Sunday, August 30, 2009

Basics of Java and getting back into programming.

Programming is just any other skill that you learn. It can be forgotten. I was asked to write a simple program called the fizzbuzz program. According to my professor, he had read an article in which this program was used as test during a job interview. Link. What was surprising was that the articles says that a majority of computer science graduates are incapable of doing this or they take an extraordinary amount of time to solve this problem.


What the fizzbuzz problem asks for is to print a number from 1-100 or whatever the range. Whenever there is a multiple of 3, the word fizz would be printed in it's place. Whenever there is a multiple of 5, the word buzz would be printed instead. And the third condition is that whenever there is a number that is the multiple of both 3 and 5, the word fizzbuzz would be printed. Seems simple right? I tried it out for myself as well. Here's the code in Java:

public class fizzbuzz {
    public static void main(String[] args) {
         for(int i = 1; i<= 100; i++){
                 if(i%15==0){
                     System.out.println("fizzbuzz");
                 }
                else if(i%3==0){
                     System.out.println("fizz");
                 }
                 else if(i%5==0){
                     System.out.println("buzz");
                 }
                 else{
                     System.out.println(i);
                 }
             }
        }
}

This program took about 3 minutes to implement, counting start-up time for my eclipse editor and compiling. Although it was easy because I knew what I needed to do already, it still took some time to figure out the mechanics. The very first time I tried this, it more than 5 minutes because I had not programmed in java for quite awhile, not to mention the programs associated with the installation of Java and using an IDE. I think that is one of the major problems with those cs graduates. Programming requires practice, and quoting a cliché, "if you don't use it, you lose it."

This fizzbuzz program is not a complex program at all to implement. What I think cs graduates and programmers have to realize is that, programming needs to be viewed as being as important as doing simple math or knowing how to speak English. It's the basis for their career and if that's not up to par, they're at a disadvantage.

The basics are the fundamental to software engineering. Being able to write up this fizzbuzz program brought me back to reality about what I need to know. This experience has taught me that quality programming may be a goal for software engineering, but you need to know how to program first.

No comments:

Post a Comment