Sunday, August 30, 2009

FizzBuzz: Welcome to Software Engineering

FizzBuzz is the first Java program that I've worked on since Fall 2008. My courses last Spring were about different scripting languages and database so my Java is pretty rusty. The goal of this program is to print out the numbers 1 to 100 with a few twists. When the current number is a multiple of 3, print "Fizz", when the current number is a multiple of 5, print "Buzz", and when the current number is a multiple of 3 and 5, print "FizzBuzz". The following code is my implementation of the FizzBuzz program.

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 % 5 == 0) {
System.out.println
("Buzz");
} else if (i % 3 == 0) {
System.out.println
("Fizz");
} else {
System.out.println
(i);
}
}
}
}

Once I got the algorithm of the program, it took me about five minutes to type and fix my errors in Eclipse. I did not have any problems with Eclipse or Java because I had everything set up even before I took ICS 413.

Before I typed this code in Eclipse, Professor Johnson gave this problem to us as our first quiz to be written on a piece of paper. Without having done some Java coding in a while, I was clueless on how to code this problem. I got the algorithm correct but my mind is still fresh with all the scripting languages I learned last semester. I realized that I have to practice more so that I don't fall behind in the later assignments. I'm hoping to come out of this class with much better knowledge and techniques on developing softwares.

David Joel Lazaro

0 comments:

Post a Comment