Subscribe:

ads

Pages

Monday 12 March 2012

Napoleon's speech to Java Code

Suddenly find something interested here:
http://bbs.wenxuecity.com/joke/430983.html

Please don't blame me that most of the characters are Chinese. What attracts me is the Java version of Napoleon's speech:

"My enemies are many,my equals are none. In the shade of olive trees,they said Italy could never be conquered.In the land of pharoahs and kings, they said Egypt could never be humbled.In the realm of forest and snow,they said russia could never be tamed.Now they say nothing.They fear me ,like a force of nature,a dealer in thunder and death.I say I am Napoleon,I am emperor……..Burn it"

So the Java version is:

import java.util.HashSet;

public class Napoleon {

    private HashSet enemies = new HashSet();

    // cdps = Chrysanthemum Damage Per Second
    public int cdpm = 100000;

    Napoleon() {

        enemies.add(new Enemy(“Italy”, 100));
        enemies.add(new Enemy(“Egypt”, 100));
        enemies.add(new Enemy(“Russia”, 100));

    }

    private void speak(){

        System.out.println(“My enemy number: ” + enemies.size());
        HashSet trueEnemies = new HashSet();
        for (Enemy e : enemies) {
             if (e.cdpm > cdpm)
             trueEnemies.add(e);
        }

        System.out.println(“The number of enemies who can beat me: ” + trueEnemies.size());

        for (Enemy e : enemies) {
            do {
                 e.shout();

            } while (e.canBeatNapoleon(this));
        }

        for (Enemy e : enemies) {
            e.shout();

        }
        cdpm = 10000000; 
        System.out.println(“I am Napoleon cdpm ” + cdpm);
        System.out.println(“Dispose enemy list…”);
        enemies.clear();
        System.out.println(“Enemy list disposed!”);
   }

   public static void main(String[] args) {
        (new Napoleon()).speak();
   }

}

class Enemy {

    private String name;

    public int cdpm;

    Enemy(String name, int cdpm) {

        this.name = name;
        this.cdpm = cdpm;
    }

    public void shout() {
        if (cdpm > 0)
            System.out.println(name + ” says: we are invincible!!!”);
        else System.out.println(name + ” says: ……”);
    }

    public boolean canBeatNapoleon(Napoleon n) {

        if (cdpm < n.cdpm) {
            cdpm = -1;
            return false;
        }
        return true;

    }

}
 
 
And the output is:
 
 My enemy number: 3
 The number of enemies who can beat me: 0
 Egyptsays: we are invincible!!!
 Italysays: we are invincible!!!
 Russiasays: we are invincible!!!
 Egyptsays: ……
 Italysays: ……
 Russiasays: ……
 I am Napoleon cdpm 10000000
 Dispose enemy list…
 Enemy list disposed! 
 
 
Well, someone wants to translate some English speech or poem to Java or javascript? Maybe we can try Martin Luther King's "I have a dream"?

No comments:

Post a Comment