Wednesday, August 27, 2008

FizzBuzz

Back in 2004 when I first started learning Java, I was using Emacs and university’s unix system to type out my Java programs, compiling, and running them in the unix system. I heard of Eclipse editor (www.eclipse.org) from fellow classmates but never look into it. This is the first time I am using Eclipse editor program for a Java program. This is the problem I have to code into a Java program:

The FizzBuzz program should print out all of the numbers from 1 to 100, one per line, except that when the number is a multiple of 3, you print "Fizz", when a multiple of 5, you print "Buzz", and when a multiple of both 3 and 5, you print "FizzBuzz".

My Java skills have been in dormant for two years, so I had to dig up my notes that I took in my Java classes and refresh my memory on Java. In addition, did some research on Java codes to bring my Java coding skills out of sleep mode. This is my Java program to the FizzBuzz program:

/*
*Ka Hung Phillip Lau
*ICS 413, Fall 2008
*FizzBuzz.java
*Credit goes to my ICS 413 classmates for the code we did in class
*/
public class FizzBuzz {
public static void main (String [] args) {
String checked = new String ();
for (int n = 1; n < style="font-style: italic;">
checked = calculateVal(n);

System.out.print(checked + " ");
System.out.println(" ");
}
}
public String calculateVal(int num) {
String result = new String();
if (num % 15 == 0) {
result = "FizzBuzz";
}
else if (num % 3 == 0) {
result = "Fizz";
}
else if (num % 5 == 0) {
result = "Buzz";
}
else {
result = num + " ";
}
return result;
}
}

It took me around 20 minutes to get the program executing with the correct results – it took long because I had to refresh my memory on how to code in Java with my notes and learning how to use Eclipse – first time using it, had to try out the whole editor to get a hang of it.

Eclipse is awesome comparing it to Emacs, it have this “dynamic” checking that checks for typos and errors that Emacs does not have. One other great thing is that Eclipse that suggestion combo boxes that pops up if it thinks that line of code in wrong – I love it! Save me time from debugging! Another great thing is that I do not need to compile it, - WOW! Eclipse magically does it for me (Awesome). I do not see Emacs do that for me.

Blog is up

Yes! Phillip Lau's Engineering Blog is up and running. Blogging about ICS 413 Software Engineering stuff - my thoughts about the assignments, programs, and codes.

Read and enjoy!