<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KirkHings.com &#187; Java</title>
	<atom:link href="http://kirkhings.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://kirkhings.com</link>
	<description>The '-berger' part trips up so many folks that I sometimes simplify my name for you. Yes, just for you.</description>
	<lastBuildDate>Sat, 13 Jun 2009 18:35:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Phrase-O-Matic Consultant Wisdom via Java</title>
		<link>http://kirkhings.com/code/java/phrase-o-matic-consultant-wisdom-via-java/419/</link>
		<comments>http://kirkhings.com/code/java/phrase-o-matic-consultant-wisdom-via-java/419/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 18:35:59 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[head first java]]></category>
		<category><![CDATA[randomizer]]></category>
		<category><![CDATA[self-instructional challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=419</guid>
		<description><![CDATA[ photo credit: schedetzki
Challenge: Create three lists of buzzwords typically used by business consultants. Randomly select three words and put in a sentence to form something ridiculous that a business consultant might say with an air of authority.

My solution:

package phraseomatic;

/**
 *
 * @author kirkster
 */
public class Main {

    /**
    [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/java/bottles-of-beer-song-via-java/388/' rel='bookmark' title='Permanent Link: Bottles of Beer Song via Java'>Bottles of Beer Song via Java</a> <small> photo credit: NUCO This programming challenge is from the...</small></li>
<li><a href='http://kirkhings.com/code/java/plain-and-recursive-factorials-with-full-print-enhancements/239/' rel='bookmark' title='Permanent Link: Plain and Recursive Factorials with Full Print Enhancements'>Plain and Recursive Factorials with Full Print Enhancements</a> <small> photo credit: gadl This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/random-image-display-with-javascript/406/' rel='bookmark' title='Permanent Link: Random Image Display with JavaScript'>Random Image Display with JavaScript</a> <small> photo credit: davidChief This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/random-bingo-card-generator-with-ajax-reset/224/' rel='bookmark' title='Permanent Link: Random BINGO Card Generator with Ajax Reset'>Random BINGO Card Generator with Ajax Reset</a> <small> photo credit: Keees This programming challenge is from a...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/28590840@N08/2660235237/" title="Peter Schedetzki" target="_blank"><img src="http://farm4.static.flickr.com/3065/2660235237_2c202c38a3.jpg" alt="Peter Schedetzki" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-nd/2.0/" title="Attribution-NoDerivs License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/28590840@N08/2660235237/" title="schedetzki" target="_blank">schedetzki</a></small></div>
<blockquote><p>Challenge: Create three lists of buzzwords typically used by business consultants. Randomly select three words and put in a sentence to form something ridiculous that a business consultant might say with an air of authority.
</p></blockquote>
<p>My solution:</p>
<pre class="brush: java;">
package phraseomatic;

/**
 *
 * @author kirkster
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // create three word sets to build from
        String[] wordListOne = {&quot;24/7&quot;, &quot;multi-Tier&quot;, &quot;30,000 foot&quot;, &quot;B2B&quot;, &quot;win-win&quot;, &quot;front-end&quot;, &quot;web-based&quot;, &quot;pervasive&quot;, &quot;smart&quot;, &quot;six-sigma&quot;, &quot;critical-path&quot;, &quot;dynamic&quot;};
        String[] wordListTwo = {&quot;empowered&quot;, &quot;sticky&quot;, &quot;value-added&quot;, &quot;oriented&quot;, &quot;centric&quot;, &quot;distributed&quot;, &quot;clustered&quot;, &quot;branded&quot;, &quot;outside-the-box&quot;, &quot;positioned&quot;, &quot;networked&quot;, &quot;focused&quot;, &quot;leveraged&quot;, &quot;aligned&quot;, &quot;targeted&quot;, &quot;shared&quot;, &quot;cooperative&quot;, &quot;accelerated&quot;, &quot;semantic&quot;};
        String[] wordListThree = {&quot;process&quot;, &quot;tipping-point&quot;, &quot;solution&quot;, &quot;architecture&quot;, &quot;core competency&quot;, &quot;strategy&quot;, &quot;mindshare&quot;, &quot;portal&quot;, &quot;space&quot;, &quot;vision&quot;, &quot;paradigm&quot;, &quot;mission&quot;};

        // determine how many words in each list
        int oneLength = wordListOne.length;
        int twoLength = wordListTwo.length;
        int threeLength = wordListThree.length;

        // generate three random numbers
        int rand1 = (int) (Math.random() * oneLength);
        int rand2 = (int) (Math.random() * twoLength);
        int rand3 = (int) (Math.random() * threeLength);

        // build a phrase
        String phrase = wordListOne[rand1] + &quot; &quot; + wordListTwo[rand2] + &quot; &quot; + wordListThree[rand3];

        // print out the phrase
        System.out.println(&quot;Consultant says: \&quot;We need a &quot; + phrase + &quot;!\&quot;&quot;);
    }

}
</pre>
<p>Here is the output:</p>
<div id="attachment_420" class="wp-caption alignleft" style="width: 410px"><img src="http://kirkhings.com/wp-content/uploads/phraseomatic.png" alt="Phrase-O-Matic pumps out business consultant wisdom" title="phraseomatic" width="400" height="414" class="size-full wp-image-420" /><p class="wp-caption-text">Phrase-O-Matic pumps out business consultant wisdom</p></div>
<p>This programming challenge is from the Head First Java book, which I studied and practiced spring 2009. The end result itself is not terribly sexy, but I liked the algorithm construction process. My programming curriculum changed course during the first year, and they eliminated our Java classes. I was still curious about Java, so I took it upon myself to self-learn Java. This was one of my first products.</p>
<p>I post these self-instructional challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it. Finally, self-instructional challenges are interesting and different than academic challenges because I sought, discovered, and performed them on my own volition without anyone else telling me to do so. I did it because I wanted to learn and practice.</p>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/java/bottles-of-beer-song-via-java/388/' rel='bookmark' title='Permanent Link: Bottles of Beer Song via Java'>Bottles of Beer Song via Java</a> <small> photo credit: NUCO This programming challenge is from the...</small></li>
<li><a href='http://kirkhings.com/code/java/plain-and-recursive-factorials-with-full-print-enhancements/239/' rel='bookmark' title='Permanent Link: Plain and Recursive Factorials with Full Print Enhancements'>Plain and Recursive Factorials with Full Print Enhancements</a> <small> photo credit: gadl This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/random-image-display-with-javascript/406/' rel='bookmark' title='Permanent Link: Random Image Display with JavaScript'>Random Image Display with JavaScript</a> <small> photo credit: davidChief This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/random-bingo-card-generator-with-ajax-reset/224/' rel='bookmark' title='Permanent Link: Random BINGO Card Generator with Ajax Reset'>Random BINGO Card Generator with Ajax Reset</a> <small> photo credit: Keees This programming challenge is from a...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/java/phrase-o-matic-consultant-wisdom-via-java/419/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bottles of Beer Song via Java</title>
		<link>http://kirkhings.com/code/java/bottles-of-beer-song-via-java/388/</link>
		<comments>http://kirkhings.com/code/java/bottles-of-beer-song-via-java/388/#comments</comments>
		<pubDate>Sun, 24 May 2009 19:42:03 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[head first java]]></category>
		<category><![CDATA[self-instructional challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=388</guid>
		<description><![CDATA[ photo credit: NUCO
This programming challenge is from the Head First Java book, which I studied and practiced spring 2009. The end result itself is not terribly sexy, but I liked the algorithm construction process. My programming curriculum changed course during the first year, and they eliminated our Java classes. I was still curious about [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/java/phrase-o-matic-consultant-wisdom-via-java/419/' rel='bookmark' title='Permanent Link: Phrase-O-Matic Consultant Wisdom via Java'>Phrase-O-Matic Consultant Wisdom via Java</a> <small> photo credit: schedetzki Challenge: Create three lists of buzzwords...</small></li>
<li><a href='http://kirkhings.com/code/java/plain-and-recursive-factorials-with-full-print-enhancements/239/' rel='bookmark' title='Permanent Link: Plain and Recursive Factorials with Full Print Enhancements'>Plain and Recursive Factorials with Full Print Enhancements</a> <small> photo credit: gadl This programming challenge is from a...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/89046340@N00/107340991/" title="PA300108" target="_blank"><img src="http://farm1.static.flickr.com/51/107340991_b1bda6f04d.jpg" alt="PA300108" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/89046340@N00/107340991/" title="NUCO" target="_blank">NUCO</a></small></div>
<p>This programming challenge is from the Head First Java book, which I studied and practiced spring 2009. The end result itself is not terribly sexy, but I liked the algorithm construction process. My programming curriculum changed course during the first year, and they eliminated our Java classes. I was still curious about Java, so I took it upon myself to self-learn Java. This was one of my first products.</p>
<p>I post these self-instructional challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it. Finally, self-instructional challenges are interesting and different than academic challenges because I sought, discovered, and performed them on my own volition without anyone else telling me to do so. I did it because I wanted to learn and practice.</p>
<blockquote><p>Challenge: Create a simple program which outputs the classic &#8220;99 Bottles of Beer&#8221; song, counting down from 99 to 0 bottles. In addition to outputting the correct number of bottles in each chorus, output the correct plural or singular form of &#8220;bottle&#8221; where appropriate to the number remaining. When there are no more bottles left then state final line.
</p></blockquote>
<p>My solution:</p>
<pre class="brush: java;">
package bottlesofbeer;

/**
 *
 * @author kirk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // initialize starting number of bottles on wall
        int beerNum = 99;

        // initialize plural form of bottle used most often
        String word = &quot;bottles&quot;;

        while (beerNum &gt; 0) {
            // if only 1 bottle is left then change to singular form
            if (beerNum == 1) { word = &quot;bottle&quot;; }

            // output song chorus using current variable states
            System.out.println(beerNum + &quot; &quot; + word + &quot; of beer on the wall,&quot;);
            System.out.println(beerNum + &quot; &quot; + word + &quot; of beer!&quot;);
            System.out.println(&quot;Take one down, pass it around.&quot;);

            // decrement beerNum cuz we took one down and passed it around
            beerNum--;
            if (beerNum == 1) { word = &quot;bottle&quot;; }

            // so long as there are still bottles on the wall
            if (beerNum &gt; 0) {
                System.out.println(beerNum + &quot; &quot; + word + &quot; of beer on the wall!&quot;);
                System.out.println();
            }
            // when there are no more bottles on the wall
            else {
                System.out.println(&quot;No more bottles of beer on the wall!&quot;);
            } // ends if/else
        } // ends while loop
    } // ends main method
} // ends class
</pre>
<p>Here is the output:</p>
<div id="attachment_394" class="wp-caption alignleft" style="width: 310px"><img src="http://kirkhings.com/wp-content/uploads/beersong-java.png" alt="99 Bottles of Beer Song output via Java" title="beersong-java" width="300" height="454" class="size-full wp-image-394" /><p class="wp-caption-text">99 Bottles of Beer Song output via Java</p></div>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/java/phrase-o-matic-consultant-wisdom-via-java/419/' rel='bookmark' title='Permanent Link: Phrase-O-Matic Consultant Wisdom via Java'>Phrase-O-Matic Consultant Wisdom via Java</a> <small> photo credit: schedetzki Challenge: Create three lists of buzzwords...</small></li>
<li><a href='http://kirkhings.com/code/java/plain-and-recursive-factorials-with-full-print-enhancements/239/' rel='bookmark' title='Permanent Link: Plain and Recursive Factorials with Full Print Enhancements'>Plain and Recursive Factorials with Full Print Enhancements</a> <small> photo credit: gadl This programming challenge is from a...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/java/bottles-of-beer-song-via-java/388/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plain and Recursive Factorials with Full Print Enhancements</title>
		<link>http://kirkhings.com/code/java/plain-and-recursive-factorials-with-full-print-enhancements/239/</link>
		<comments>http://kirkhings.com/code/java/plain-and-recursive-factorials-with-full-print-enhancements/239/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 04:00:56 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[factorial]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[self-instructional challenge]]></category>
		<category><![CDATA[wibit]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=239</guid>
		<description><![CDATA[ photo credit: gadl
This programming challenge is from a WiBit.net instructional video, which I studied/practiced this spring 2009. The end result itself is not terribly sexy, but I liked the algorithm construction process. My programming curriculum changed course during the first year, and they eliminated our Java classes. I was still curious about Java, so [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/java/bottles-of-beer-song-via-java/388/' rel='bookmark' title='Permanent Link: Bottles of Beer Song via Java'>Bottles of Beer Song via Java</a> <small> photo credit: NUCO This programming challenge is from the...</small></li>
<li><a href='http://kirkhings.com/code/java/phrase-o-matic-consultant-wisdom-via-java/419/' rel='bookmark' title='Permanent Link: Phrase-O-Matic Consultant Wisdom via Java'>Phrase-O-Matic Consultant Wisdom via Java</a> <small> photo credit: schedetzki Challenge: Create three lists of buzzwords...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/24183489@N00/279433682/" title="GEB Recursive" target="_blank"><img src="http://farm1.static.flickr.com/91/279433682_23ac618518.jpg" alt="GEB Recursive" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/24183489@N00/279433682/" title="gadl" target="_blank">gadl</a></small></div>
<p>This programming challenge is from a WiBit.net instructional video, which I studied/practiced this spring 2009. The end result itself is not terribly sexy, but I liked the algorithm construction process. My programming curriculum changed course during the first year, and they eliminated our Java classes. I was still curious about Java, so I took it upon myself to self-learn Java. This was one of my first products.</p>
<p>I post these self-instructional challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it. Finally, self-instructional challenges are interesting and different than academic challenges because I sought, discovered, and performed them on my own volition without anyone else telling me to do so. I did it because I wanted to learn and practice.</p>
<blockquote><p>Challenge: Create a simple factorial calculator in Java, using the NetBeans IDE. The original project simply output something like &#8220;5! = 120&#8243;. I improved it to output each member integer so as to clarify the factorial process, so my program output something like &#8220;5! = 1 x 2 x 3 x 4 x 5 = 120&#8243;. I like to push projects a little farther than the original, just to satisfy myself or to learn more.
</p></blockquote>
<p>My solution:</p>
<pre class="brush: java;">
package factorial;
/**
 * @author kirkster
 */
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int n;
        int i;
        int factorial = 7;
        int result= 1;
        System.out.print(factorial + &quot;! = &quot;);
        for (i = 1; i &lt;= factorial; i++) {
            System.out.print(i);
            if (i &lt; factorial) {
                System.out.print(&quot; x &quot;);
            }
        }
        for (i = 1; i &lt;= factorial; i++) {
            result = fact(i);
        }
        System.out.print(&quot; = &quot; + result);
        System.out.println(&quot;&quot;);
    }

    static int fact(int n) {
        int i;
        int result = 1;
        for (i = 1; i &lt;= n; i++) {
            result *= i;
        }
        return result;
    }
}
</pre>
<p>After this first factorial program, I did a WiBit video doing the same thing using a recursive algorithm. It accomplishes the same thing but in a computer-scientist-sexier way:</p>
<pre class="brush: java;">
package recursivefactorial;
/**
 * @author kirkster
 */
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println(factorial(n));
    }

    public static long factorial(int n) {
        if (n &lt; 0)
            return -1;
        else if (n == 0)
            return 1;
        else
            return n * factorial(n -1);
    }
}
</pre>
<p>After doing both programs, I wanted to enhance the recursive version with the full step printouts like I did in the first plain version. It was a bit trickier to implement printing out each member integer like my previous improvement, and I could only print the member integers in backwards format (avoiding an extra loop) but this was my solution:</p>
<pre class="brush: java;">
package recursivefactorial;
/**
 * @author kirkster
 */
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int n = 7;
        System.out.print(n + &quot;! = &quot;);
        System.out.println(factorial(n));
    }

    public static long factorial(int n) {
        if (n &lt; 0)
            return -1;
        else if (n == 0) {
            System.out.print(&quot; = &quot;);
            return 1;
        }
        else {
            if (n == 1)
                System.out.print(n);
            else
                System.out.print(n + &quot; x &quot;);
            return n * factorial(n -1);
        }
    }
}
</pre>
<p>Here is the output:</p>
<div id="attachment_241" class="wp-caption alignleft" style="width: 356px"><img src="http://kirkhings.com/wp-content/uploads/recursivefactorial.png" alt="Output from a recursive factorial algorithm built in Java" title="recursivefactorial" width="346" height="119" class="size-full wp-image-241" /><p class="wp-caption-text">Output from a recursive factorial algorithm built in Java</p></div>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/java/bottles-of-beer-song-via-java/388/' rel='bookmark' title='Permanent Link: Bottles of Beer Song via Java'>Bottles of Beer Song via Java</a> <small> photo credit: NUCO This programming challenge is from the...</small></li>
<li><a href='http://kirkhings.com/code/java/phrase-o-matic-consultant-wisdom-via-java/419/' rel='bookmark' title='Permanent Link: Phrase-O-Matic Consultant Wisdom via Java'>Phrase-O-Matic Consultant Wisdom via Java</a> <small> photo credit: schedetzki Challenge: Create three lists of buzzwords...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/java/plain-and-recursive-factorials-with-full-print-enhancements/239/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
