Pages

Sunday, September 25, 2016

Hello! Let's go! (Java)

abstract class Earthling {
    String name;
    String country;
    String favoriteBook;
    Earthling(String name, String country, String favoriteBook) {
        this.name = name;
        this.country = country;
        this.favoriteBook = favoriteBook;
    }
    void say(String anything) {
        String output = this.name;
        output += " (" + this.placeOfOrigin() + "): ";
        output += anything;
        System.out.println(output);
    }
    abstract void sayHello();
    abstract void sayLetsGo();
    String placeOfOrigin() {
        return this.country;
    }
}

class Mexican extends Earthling {
    Mexican(String name, String favoriteBook) {
        super(name, "Mexico", favoriteBook);
    }
    void sayHello() {
        this.say("Hola!");
    }
    void sayLetsGo() {
        this.say("Vamonos!");
    }
}

class Actors {
    static Mexican dora = new Mexican("Dora the Mall Explorer", "Good Score, Dora!");
}

class Scene {
    static void perform() {
        Actors.dora.sayHello();
        Actors.dora.sayLetsGo();
    }
    
    public static void main(String[] args) {
        perform();
    }
}