Wednesday, August 27, 2008

Assignment 4: FizzBuzz

/* Aric West
* ICS 413
* August 27, 2008
* Assignment 4
* FizzBuzz.java
*
* This program prints out numbers from 1 to 100, however numbers that are evenly
* divisible by 3 print Fizz instead, those evenly divisible by 5 print
* Buzz instead, and if divisible by both, FizzBuzz is printed.
*/

public class FizzBuzz {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
System.out.println(getFizzBuzz(i));
}
}

public static String getFizzBuzz(int number) {
if (number % 3 == 0 && number % 5 == 0)
return "FizzBuzz";
if (number % 3 == 0)
return "Fizz";
if (number % 5 == 0)
return "Buzz";
return Integer.toString(number);
}
}


Total elapsed time from opening Eclipse until starting this blog post: 21 minutes. However, I did manage to distract myself on several occasions and could have easily finished in half of that time. While I did not take notes during our first class, I liked the style presented during the lecture and my code I believe resembles that. Java is definitely not my most comfortable language, but I have a reasonable appreciation for the beauty and style of object oriented languages and do not believe I'll have too much trouble getting along. I had no errors when I ran the code the first time as Eclipse quickly pointed out the little things I'd forgotten. The most difficult part, which required 10 seconds on google, was converting the integer to a string. I didn't encounter any problems with Eclipse, though I had already previously installed it on my computer.

In our brief time in this class, and in regards to this assignment the most important thing I think I've been reminded of is that there's almost always a different way to solve a given problem, and quite likely there's also a better way... maybe!