Conor Mac Aoidh
http://macaoidh.name
conor@macaoidh.name
 

Search

Archives

  • July 2010
  • June 2010
  • April 2010
  • March 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008

Spam

4,729 spam comments
blocked by
Akismet

Tag Cloud

    bt broadband CMS conor's management system conormacaoidh conor mac aoidh content management system drums fast Fedora fedora 10 furasta furasta cms furasta org gnome guide hello world HTML icsp iPhone Java javascript joomla kde Linux Mandriva mc kennas Monaghan Music mysql php repository Scratch stealing the ceiling The Dominican Affair the pot smoking pirates the strats tutorial Twitter updates web design forum webme webworks weekly tweets Windows wordpress

Ads

Java – Drawing Squares

Posted Dec 5th, 2009 by Conor in in College,Java,Languages

This weeks ICSP assignment was to write a program which draws squares. The task was to draw squares from a set list in an array, but I opted rather to accept a command line argument in my script. To write this I had to delve back into regular expression, which I hate because I don’t understand!

The program source is below. You should execute the program from the command line giving the with and height of the square you wish to draw, for example:

java Squares 4x4

And the code:

import java.lang.String;
import java.util.regex.*;

public class Squares{
        public int dimensions[];

        public Squares(String[] args){
                if(args.length==1){
                        Pattern form=Pattern.compile("^\\S+x\\S+$");
                        Matcher fit=form.matcher(args[0]);
                        if(fit.matches()){
                                try{
                                        String[] dims=args[0].split("x");
                                        int width=Integer.parseInt(dims[0]);
                                        int height=Integer.parseInt(dims[1]);
                                        this.dimensions=new int[] {width,height};
                                }
                                catch(NumberFormatException e){
                                        System.err.println("Argument must be a string, width by height, in the form 6x6");
                                        System.exit(1);
                                }
                        }
                        else{
                                System.out.println("Argument must be a string, width by height, in the form 6x6");
                                System.exit(1);
                        }
                }
                else{
                        System.err.println("Please supply an argument, which must be a string, width by height, in the form 6x6");
                        System.exit(0);
                }
        }

        public String draw(){
                int i;
                int z;
                int width=this.dimensions[0];
                int height=this.dimensions[1];
                String square="";

                for(i=0;i<height ;i++){
                        for(z=0;z<width;z++){
                                if((i==0||i==height-1)&&(z==0||z==width-1))
                                        square+="+";
                                else if(z==0||z==width-1)
                                        square+="|";
                                else if((i==0||i==height-1))
                                        square+="-";
                                else
                                        square+=" ";
                        }
                        square+="\n";
                }

                return square;
        }

        public static void main(String[] args){
                Squares square=new Squares(args);
                String draw=square.draw();
                System.out.println(draw);
        }
}
No responses yet

Java – Project Euler Multiples

Posted Nov 21st, 2009 by Conor in in Java,Languages

This weeks ICSP assignment was one of the Project Euler challenges. Here is the task:

This weeks Bonus Task is to solve the First Problem using Java:
“If we list all the natural numbers below 10 that are multiples of 3
or 5, we * get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.”

In the code below, I have achieved this objective and also expanded on it. My program allows you to pass on two multiples and a max integer value to the program for which to calculate the results. You can execute:

java Multiples 3 5 1000

That command will find the sum of multiples of 3 and 5 below 1000, as stated in the task. You can also change the values to calculate different sums. The code for Multiples.java is below:

/*
 * Developer:   Conor Mac Aoidh
 * Homepage:    http://blog.macaoidh.name/2009/11/21/java-project-euler-multiples/
 */

public class Multiples{
        public static void main(String[] args){
                Multiples multiples=new Multiples();
                int one=0;
                int two=0;
                int max=0;
                if(args.length==3){
                        try{
                                one=Integer.parseInt(args[0]);
                                two=Integer.parseInt(args[1]);
                                max=Integer.parseInt(args[2]);
                        }
                        catch(NumberFormatException e){
                                System.err.println("Argument must be an integer");
                                System.exit(1);
                        }
                }
                else
                        System.out.println("You must supply integers in the format:\n multiple_one multiple_two max_integer");

                int sum=multiples.sum(one,two,max);

                System.out.println("Find the sum of all the multiples of "+one+" or "+two+" below "+max);
                System.out.println("Sum:"+sum);
        }

        public int sum(int one,int two,int max){
                int i=0;
                int sum=0;
                for(i=0;i<max ;i++){
                        if(i % one==0)
                                sum=sum+i;
                        if(i % two==0)
                                sum=sum+i;
                }
                return sum;
        }
}

Simple as that!

3 responses so far

ICSP Week One Assignment

Posted Oct 25th, 2009 by Conor in in College,Games,Java,Languages

I started a course in UCD last week called “Introduction to Computer Science and Programing”, or ICSP. It’s gonna be going on for three months and then I will have a big exam which I will probably fail!

The whole course centers around the use of Java, I’m not sure yet if we are going to be using anything else. We haven’t actually even started with Java yet, but we are using this program called Scratch to program our Java for us! I wouldn’t say that it is the Dream-weaver of Java, far from it. In fact I think that it is a great method of getting into Java. It has a set of preconfigured code which you can arrange into blocks, which then run – quite similar to the source of Java actually except simplified. It also eliminates the need for compiling.

Last week I went to my first “lecture” which was good enough, but I learned something valuable that day; computer hardware is not the road that I want to go down! I didn’t really enjoy the hardware aspect of the day but when it came to the Scratch lessons I was flying! For our first assignment we had to write a game in Scratch, which is essentially it’s own unique programing language. The game is called “Capture the Flag”. I was actually flat out all week and didn’t get a chance to start work on it until today, which is coincidentally the deadline for it’s completion! I spent about three hours making the game, here’s the manual and the game:

Capture The Flag

Overview
Capture the flag is a simple two player game which involves stealing the flag from the opposite colours corner.

Controls
Blue Player
Up Arrow Key = Move Up
Down Arrow Key = Move Down
Left Arrow Key = Move Left
Right Arrow Key = Move Right

Red Player
W Key = Move Up
S Key = Move Down
A Key = Move Left
D Key = Move Right

Rules
To gain a point a player must capture the opposite colour flag and return it to their base (the starting point).

If a player is in possession of a flag and his opponent touches him the flag is returned to it’s base and the player to his base.

To win a player must gain three points.

Faults
The one fault with the game is that, at least on my computer, when one player is using the keyboard to move the other player cannot move simultaneously. Although this is a fault it does also make the game a bit more interesting because the players have to fight even to move!

Learn more about this project

No responses yet

One Year of macaoidh.name

Posted Sep 22nd, 2009 by Conor in in Games,Java,Me,My Blog,The Dominican Affair

Would you believe it? It’s the first anniversary of my Blog! I have officially been ranting about shite for a whole year!

Anyway to celebrate the birthday of my Blog I decided to do it up a wee bit. I added a nice wee sidebar to my theme, which I am actually thinking of releasing at some stage in the near future. Also I added a new download manager to http://files.macaoidh.name . It is very useful; it keeps track of how many people are downloading what. Hopefully in the future it will give me an idea of what people that view my blog like and don’t like. I will actually have to go over all my previous posts and make sure that the download links are correct considering there was a big change in the link format.

The only real reason I wrote the thing is because someone has commissioned me to do something similar, starting next week. But the commissioned work will be a bit more complete and stuff. So feel free to try and hack my system. I don’t want to find faults when I’m finished writing it and then have to go back… The manager also serves as a very useful tool for me. I have included an admin area in which I can log in, upload files and choose to store them, make them available for download or even to download + password protect them! This feature will no doubt come in handy, I like to think of it as my personal, non-user-information-gathering, version of Google Docs!

What else has been happening recently… ooh I am in the process of making/releasing an album with The Dominican Affair. It is called Stealing the Ceiling. We have our last mixing session this weekend and hope to have it available on piratebay towards the end of October! It will also be available to purchase or download at http://www.holygrailrecords.com

Just thought I’d mention that 6th year is terribly shit. I can manage to squeze about 2 hours of programing in thrice a week. Also I am doing an Introduction to Computer Science Programing course in UCD over the next few months just to prepare me for college and to make sure that I actually want to study Computer Science! It will be good craic to learn Java at that course; I plan to make a facebook application/game when I have learned Java and base it in Monaghan.

Oghgbjkc damn! I just realised that I still haven’t renewed my macaoidh.name subscription! Better get to it… three days left…..

One response so far



Conor's Blog is powered by Wordpress | Template design by Conor Mac Aoidh