Saturday, January 17, 2015

Fizz Buzz using Java and recursion

My very first little program in Eclipse :) It's honestly kinda the same as the C# would be, except printing is different. Very fun though! I am so excited to work in Java too now. Seeing things work without errors makes me very, very happy!!! :D

public class Puzzle 
{
    int i = 0;
 
    public void fizzBuzz()
    {
         i++;

         if (i % 15 == 0) System.out.println("fizz buzz");
         else if (i % 3 == 0) System.out.println("fizz");
         else if (i % 5 == 0) System.out.println("buzz");
         else System.out.println(i);
     
         if (i <= 100) fizzBuzz();
    }
}

public class App 
{ 
    public static void main( String[] args )
    {
         Puzzle fizzeh = new Puzzle();
         fizzeh.fizzBuzz();
    }
   
}

Thursday, January 15, 2015

Setup Eclipse & Java Environment (PATH & JAVA_HOME)

1. Java JDK 8:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
You can either install everything from Java JDK or skip the 3rd option (end user Java). If you don't know what I mean, just install everything and keep clicking next. Install it wherever you want and write down the path for the home directory! I installed mine here:

C:\java\jdk1.8.0_25

2. Eclipse IDE for Java Developers
Download this https://www.eclipse.org/downloads/

If you need any help with the above 2 steps, someone here has addressed a step by step with pictures:
http://www.wikihow.com/Download,-Install,-and-Run-JDK-and-Eclipse

3. (OPTIONAL if it breaks) Setup JDK to Eclipse: https://wiki.eclipse.org/Eclipse.ini https://www.youtube.com/watch?v=njsjWfwPZ2g
^ This guy shows you but you can't see the text.
Take that home directory I had you write down. Add "\bin" to it. Now..

..first go to My Computer > Properties.


Then go to Environment Varibles on the bottom right.


Go to PATH. See how I took it out onto Notepad? Find the current Java location. Check it out and paste it into windows explorer. See if its the one that is broken. If it is.. snip it out. Put your new home Java JDK directory in with "\bin". You will see the highlighted part in the screenshot. Make sure there aren't any other Java JDK lines in there. It will take from left to right, so if you did have 2 JDK paths it'd take the one on the left.. but best to get rid of any dead links anyways. Mine is:
C://javaC:\java\jdk1.8.0_25\bin
Now, put it back. Don't delete anything else. Hit ok.


If you are not using Eclipse, you may need to setup windows environment. Eclipse, however, does not use JAVA_HOME. If you are using Eclipse, skip this last screenshot.

Then check for JAVA_HOME. If you do not have it, then hit New and create one. For name put "JAVA_HOME" and for the path put in the path where you installed JDK 8 on step 2!

4. Start running Eclipse. Pt. II coming up for setting up a console app in Java..

Reverse String (C#)


Reversing a string using an array method (not doing the obvious Array.Reverse); method, it is more fun to do it with a loop!

Also incorporated the addition assignment operator (+=).

    public class ReverseString
    {
        public string ReverseIt(string phrase)
        {
            string reversed = "";
            string[] wordsArray = phrase.Split(' ');

            int length = wordsArray.Length;

            for (var i = length -1 ; i >= 0; i--)
            {
                reversed += wordsArray[i] + " ";
            }

            Console.WriteLine(reversed);
            return reversed;
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            ReverseString rev = new ReverseString();
            rev.ReverseIt("I have six locks on my door all in a row. When I go out, I lock every other one. I figure no matter how long somebody stands there picking the locks, they are always locking three.");
            Console.ReadLine();
        }
    }

Monday, January 12, 2015

Input/Output Line Count Puzzle


Files and Directories on disk puzzle: Given an input directory that is passed into the method (For example: C:\work\input_files). There will be n text files in this directory. For simplicity, all text files will end with the extension .txt. Anything else can be ignored. Each text file will contain n number of lines. Find the total number of lines in all the files. (For example, if there are 3 files, file #1 has 3 lines, file #2 has 200 lines, file #3 has 20 lines, you should return 223).

Don't forget the using statement for System.IO!!!


Fizz Buzz (C#)


Fizz Buzz Puzzle
"Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”."

This is my take on the "Fizz Buzz" puzzle. I stored it in a Dictionary so it is re-useable, but it just as easily could have been a simple Console.WriteLine(); format. I made the index of the Dictionary the int 1-100 so it could be manipulated and stored the answers to the fizz buzz as strings. I saw some neat one-line solutions with chaining if/else statements and using LINQ! It's fun how there are many ways to solve the same problem! I like how this is simple to read and logical.

And, of course the actual program calling this..

Thursday, January 8, 2015

Legends Boxing



I am excited for the new boxing gym I have joined and for the opportunity to help them out with some web design! I chose a simple responsive Twitter Bootstrap design so it is easily accessible from desktop, tablet, and mobile. I love how with Twitter Bootstrap all the classes are in place for you and they are preset to adjust with resizing. Working with the classes and CSS is very simple and their documentation is great! It only took a few hours to setup the structure and mock up some wallpaper photos as a sample draft. I will be adding content and actual photos of the gym as my next step.

The mobile version of the site can be seen below: