Wednesday, August 31, 2011

FizzBuzz

Recently I implemented the FizzBuzz programmed discussed on our first day within the Eclipse IDE. The task was to implement the FizzBuzz program within the Eclipse IDE. The time it took total was 9 minutes to code the program, in addition it took another 11 minutes to comment and verify the output of the program. JUnit wasn't used for verification and so each output was examined for its validity. The main problem I had faced was cleaning up the code, so it isn't 'messy'.  


Cleaning up the code involved creating a FizzBuzz object that handles the logic portion of the problem. The getOutput method within FizzBuzz will return a string representation of the number taken. There is still more room for improvement in the code, primarily incorporating software engineering principles in the code. Below is the source code for my FizzBuzz implementation.

1:  package edu.hawaii.ics314;  
2:    
3:  /**  
4:   * @author Jason Yeo  
5:   *   
6:   * FizzBuzz program should print out all of the numbers from 1 to 100  
7:   * one per line, except that when the number is a multiple of 3  
8:   * it will print "Fizz", when a multiple of 5, it will print "Buzz"  
9:   * and when a multiple of both 3 and 5, it will print "FizzBuzz"  
10:   */  
11:  public class FizzBuzz {  
12:    
13:       public static void main(String[] args){  
14:            FizzBuzz fb = new FizzBuzz();  
15:            for(int i = 1; i < 101; i++){  
16:                 System.out.println(fb.getOutput(i));  
17:            }  
18:       }  
19:         
20:       /**  
21:        * @param number  
22:        * @return String  
23:        *   
24:        * getOutput will accept an integer ranging from 1 to 100, and   
25:        * will return the respective String output. The String output is  
26:        * based on the requirements set by Professor Johnson in his requirements   
27:        * for the FizzBuzz program.  
28:        */  
29:       public String getOutput(int number){  
30:            if(number % 15 == 0){  
31:                 return "FizzBuzz";  
32:            }  
33:            else if(number % 3 == 0){  
34:                 return "Fizz";  
35:            }  
36:            else if(number % 5 == 0){  
37:                 return "Buzz";  
38:            }  
39:            else{  
40:                 return String.valueOf(number);  
41:            }  
42:       }  
43:  }  

Note that I had modeled my code after the solution created by the class.    

Monday, August 29, 2011

JNetTool: A Handy Networking Tool

Overview
Sourceforge holds a wide array of open source projects and to my surprise I found a Java related project that dealt with networking.  The reason I chose the JNetTool was because I am currently learning the workings of TCP/IP and all of its intricacies.  The description for JNetTool is as follows, "A network tool with gui for whois, ping, traceroute, ns lookup (dig,dns), portscan, network calculator, visual net plan - written in java."  Indeed all of the components in JNetTool makes for a handy networker's 'pocket knife'.


I will demonstrate the features within JNetTool and show that this package satisfies the three prime directives.


1. The system successfully accomplishes a useful task.
The one component within JNetTool that I was very excited to see was the Net-Calc option.  Subnetting is somewhat a tedious task for me and having a subnet calculator makes life much easier.  The Net-Calc option has all your standard subnetting options such as network class/CIDR, subnet mask, number of hosts, network and broadcast address and IP range.  

Example of the Net-Calc tool in JNetTool

What JNetTool does to go above and beyond is the option to 'show next subnet with this number of hosts', which will iterate subnets with the designated number of wanted hosts.  The PortScan option offers a basic portscanning tool.  While it is not as robust as Nmap it does its job.  

Example of a port scan done on uhunix (selected ports for brevity)

2. An external user can successfully install and use the system.
JNetTool's documentation page, holds an up to date change log and links to relevant pages. Unfortunately the developer seems to be have an extensive documentation in German, which I am unable to understand.  However within the JAR file was several .txt files describing his project.  There were no problems downloading and installing JNetTool.  Since the project was packaged as a JAR, it ran as a applet when opening it.  The fact that I was able to run JNetTool on my first try is a good indicator of this system meeting the 2nd prime directive. 

3. An external developer can successfully understand and enhance the system. 
The source code for JNetTool is available on sourceforge and is well written as it is extensively commented.  Since there are several tools within JNetTool (whois, dns, ping, traceroute, etc...) the source code is somewhat large and would take time for me to fully read and understand how it works.  However this is a minor problem since the code is structured and commented well.  

Example of the source code for JNetTool (BrowserLauncher.java)

Overall I feel that running and examining JNetTool was a great way to get my feet wet in the realm in software engineering.  I would love to venture out and possibly create/enhance JNetTool in the future. I believe I'll find motivation in the great words of Captain Jean Luc-Picard... "make it so"

Wednesday, August 24, 2011

Hello Blog;

//First post for ICS 314.  I hope to cover many of my interests and related topics in this blog.