Wednesday, August 27, 2008

Purpose: The purpose of this assignment is to create a java application that counts from 1 to 100. The number is then tested to check if is divisible by 3, 5, or 3 and 5, which will print out Fizz, Buzz, or FizzBuzz (in respective order) instead of the number.

Problems: The main problem I had for this assignment was getting used to using the program Eclipse. This being my first time to use it, I had problems starting a new java project, and then also making the java class file. Once I got those issues out of the way, the main problem was compiling and running the application for testing.

Solution: The way I overcame the problems I listed above was just too simply use the built-in tutorial. I used the simple tutorial on building a “Hello World” project, which guided me to everything I needed.

Conclusion: The assignment took me about 18 minutes to implement, including the time to figure out how to use Eclipse. After using the program, I see now that it’s a very good useful tool in code implantation. I’ve always heard of people using Eclipse, but never bothered to use it, I’ve always used Jcreator, Textpad, or even Notepad. Eclipse is similar to Jcreator, both being able to start java project and automatically put in the ending squiggly brackets for you. The difference I’ve seen so far, between the two is that Eclipse notifies you of a syntax error right away, before running the application.

Code:


public class FizzBuzz {

// This Method will print Fizz, Buzz, or FizzBuzz depending on the integer
public static void printFB(int i){

if(i%3==0 && i%5==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);
}
}

// Main to test the method printFB
public static void main(String[] args) {

//Test Cases
System.out.println("Test Cases");
printFB(53);
printFB(5);
printFB(21);
printFB(15);
printFB(0);
printFB(1);
System.out.println();

// For Loop from 1 to 100
for(int i = 1; i <= 100; i++){
printFB(i);
}

}
}