Tuesday, August 30, 2011

FizzBuzz in Eclipse

For this assignment we were tasked with writing the "FizzBuzz" program, which we walked through in an earlier class. What the FizzBuzz program does is print out all numbers from 1 to 100, with a few exceptions:

  • If the number is a multiple of 3,the program replaces the number with "Fizz"
  • If the number is a multiple of 5, the program replaces the number with "Buzz"
  • If the number is a multiple of both 3 and 5, the program replaces the number with "FizzBuzz"
The code I've written for this program is as follows:


Completion of the program took about 10 minutes. I originally started with an alternate approach to the problem, which took an int array of size 100, and when put through a for loop gave each int within the array a value of either 0,1,2, or 3 depending on whether it was a multiple of 3,5,3&5, or none of the above, respectively. After this process was done, the completed array would go through another for loop, which printed out "Fizz", "Buzz", "FizzBuzz", or just the number depending on the value in the array. After  some consideration, I realized that given the simplicity of this problem there were no advantages to doing it this way, and had this problem been on a larger scale, my original method would have been less efficient and more processor-intensive. Thus, I rewrote the program using the method we covered in class.

There were some problems that I had with using eclipse, mostly with setting up a new project and java file. This was my first time using this particular version of Eclipse, so I was a bit unfamiliar with the options, but thanks to my partner I was able to get past that quickly.

One of the things that I have realized through doing this program, through being in a group and helping each other out, is that working with other people can be a reassuring experience, especially when there's something that you personally do not know. Of course, it was a minor issue this time around for myself, but it was reassuring that there was someone to help me. Yet at the same time, it made me feel embarrassed that I couldn't figure out such a simple problem myself, which made me want to really review java and get up to speed so I'm not left behind and dragging my team down.

No comments:

Post a Comment