Sunday, August 30, 2009

FizzBuzz Experience

FizzBuzz is a good startup assignment. In short, the goal is to print a number from 1 to 100 on each line and if the number is a multiple of 3 print Fizz, if the number is a multiple of 5 print Buzz, and if a number is a multiple of 3 & 5 print FizzBuzz.

It took me about 15 minutes to implement the FizzBuzz in which most of the time spent on setting up a new java project in Eclipse. Rewritten the code did not take long.

When I started using Eclipse for the first time, I encountered a lot of minor challenges. One of the challenges was setting up the java project and adding new java class into the package.

After finishing the main class, I also had problem when adding the JUnit test case to the package. It took a while to get the right syntax for assertEquals and get the TestFuzzBuzz pass.

Since it’s been a long time from my undergrad that I’ve coded Java, I’ve also encountered a lot of syntax error and mistype the keywords. By using Eclipse, it's a lot easier to code, compile, and package Java project compare to using command prompt when I first learned Java programming 7 years ago.

Here’s my code for the FizzBuzz:


public class FizzBuzz {

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

    static String getFizzBuzz(int i) {
        if ((i%3==0) && (i%5==0))
            return "FuzzBuzz";
        else if (i%3==0) return "Fizz";
        else if (i%5==0) return "Buzz";
        return Integer.toString(i);     
    }
}

Here's my code for the JUnit test case:

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class TestFuzzBuzz  {
    @Test
    public void Testfuzz () {
        assertEquals("1",FizzBuzz.getFizzBuzz(1));
        assertEquals("Fizz",FizzBuzz.getFizzBuzz(3));
        assertEquals("FuzzBuzz",FizzBuzz.getFizzBuzz(15));
        assertEquals("Buzz",FizzBuzz.getFizzBuzz(5));        
    }
}

Three Prime Directive: MyJQuery v.1.0

Overview:
  • Package downloaded: MyJQuery version 1.0
  • Author: Adrabi Abderrahim
  • URL: http://myjquery.sourceforge.net/

    MyJQuery version 1.0 is a java-based database utility under open source license for executing MySQL statement released in June 2008 by Adrabi Abderrahim. MyJQuery is powered by Java Database Connection (JDBC) and run on any operating system. It is a tool that provides capability for manipulating MySQL database from simple query to complex SQL object creation. It can also export data to CSV, HTML, XML and generate code snippet of an entire schema's data in different programming languages. The key features of MyJQuery include the following:

    • Query editor: allows for the execution of single or multiple SQL statements and the result of the executed statement is displayed in the log panel which also indicate specific error message and code.
    • Database browser: allows user to view a database’s schema and tables.
    • Query snippet: allows user to insert a SQL query for quick help.
    • Export CSV, HTML, and XML data: allows for exporting data in CSV, HTML or XML format from one or more tables.
    • Generate Perl, Perl/CGI, PHP, Java & JSP code snippet: allows for generating a snippet of MySQL code from one or more tables.
    • Server database statistics: shows all statistics of the selected database.

    Prime Directive 1: MyJQuery does not satisfy the PD#1. Though the design of MyJQuery is very simple and straightforward, MyJQuery does not fully satisfy the user interaction at all. The SQL editor does not mirror the modern text editor as it does not support some keyboards and the short cut keys. For instance, the SQL editor does not support the navigator key such as page up, page down, and arrow key. Also the user can only copy and paste by right-clicking the mouse which very inconvenience. Additionally, the SQL editor does not automatically insert a line break when inserting a new query from the query snippet.

    Prime Directive 2: MyJQuery satisfy the PD#2. Any external user can download and unzip of MyJQuery from sourceforge.net site without any a problem. No installation is required for MyJQuery. The user can execute the program directly from the execution file in the package. There is no additional user-level documentation in the package to the README and LICESCE document. No java or JDBC knowledge is required; however, the user is required to have much or less SQL background to use the program. It will be very challenging for the user who has no SQL background. MyJQuery required connection to the database when it started. Users should get SQL tutorial directly from MySQL site or any developer forum if there is any syntax error from the query. There is no need for the program to provide additional tutorial on SQL.

    Prime Directive 3: MyJQuery does not fully satisfy the PD#3. External developer can find the source code of MyJQuery in the develop section on sourceforge.net site. Though, the source code is well written and placed under GNU license, it still very challenge and time-consuming if the external developers decide to extend or modify the system as there is no developer-level documentation provided in the package that.

    Conclusion: Overall, MyJQuery does not satisfy all of the three PDs. During the testing of using MyJQuery, it can only connect to the database on the local machine or within a specific location. For the key features of the system, it does not meet the user interaction. There are some frustration trying to use the query editor and try to the developer-level documentation beside the source code. Personally, I am looking for MySQL database management tool instead of just a query editor that allow connecting to the database server not only on the localhost as PHPMyAdmin is already provided a great tool to manage localhost database.

  •