Message in a Bottle #SongsInCode
SoftwareThis afternoon I did something extraordinarily productive and created an extended #SongsInCode rendition of Message in a Bottle that compiles. Now all somebody in this distant future needs to do is create a new class to fetch Sting's bottle and read his message!
Sting.java
public class Sting { public static void main(String[] args) { Bottle oceanBottle = new Bottle("SOS!"); } }
Bottle.java
public class Bottle { String message = ""; boolean opened = false; public Bottle(String message) { this.message = message; } public void pullCork() { opened = true; } public String getMessage() throws NotOpenException { if (opened) return message; else throw new NotOpenException(); } }
NotOpenException.java
public class NotOpenException extends Throwable { public NotOpenException() { super("You haven't opened the bottle yet!"); } }