FizzBuzz

Although Dr. Johnson went over this small program in class, I still took 6 minutes to create and confirm that everything was correct and documented.

One of the problems I encountered was with Eclipse’s auto complete. I have not programmed Java code for a few semesters, so I was not used to the Eclipse automatically adding closing parenthesis or braces. In the end this unfamiliarity to Eclipse added to the time it took me to program this code. Once I become familiar with this auto complete, I do no think this program should take me as long to code.

Another deficiency I foresaw was Javadoc. In prior java courses, there was not a huge stress upon using Java built in documentation. Rather, they stressed to put at least some documentation. The more I continue to use Javadocs, this style of documentation should become second nature.


public class FizzBuzz {

   /**
    * Main program to test FizzBuzz Object
    * @param args
    */
  
public static void main( String[] args )
  
{
       FizzBuzz fbObj
= new FizzBuzz();
      
for( int i = 1; i <= 100; i++ )
      
{
           System.out.println
( fbObj.output( i ) );   
      
}
   }
  
  
/**
    * Prints Fizz, Buzz, FizzBuzz, or number based upon input integer.
    * @param i
    */
  
public String output( int i )
  
{
      
return ( i % 3 == 0 && i % 5 == 0 ) ? "FizzBuzz" :
                       (
i % 5 == 0 ) ? "Buzz" :
                           (
i % 3 == 0 ) ? "Fizz" :
                              
String.valueOf( i );
  
}
}

Advertisements

One thought on “FizzBuzz

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s