Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Java 2 Micro Edition

Date:04/20/05
Author:Stefan Scheler
URL:http://sts.synflood.de/
Comments:0
Info:http://java.sun.com/j2me/
Score: (2.91 in 88 votes)
/*
 * bottles.java - 99 Bottles of Beer
 * J2ME Midlet for MIDP 1.0 compatible mobile devices, tested on nokia 6100
 * by Stefan Scheler <sts[at]synflood[dot]de> on 16-June-2004
 *
 */
 
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class bottles extends MIDlet {
    
    private Display mDisplay;
    private Form mForm;
    private StringItem mString;

    public void pauseApp() {}
    
    public void destroyApp(boolean unconditional) {}
        
    public bottles() {
        
        mString = new StringItem("", "");
        mForm = new Form("99 Bottles of Beer");
        mForm.append(mString);
        mDisplay = Display.getDisplay(this);
        mDisplay.setCurrent(mForm);
    
    }
    
    public void appendText(String s) {
    
        mString.setText(mString.getText()+s);
        
    }
    
    public void startApp() {
        
        for (int i = 99; i > 1; i--) {
            int j = i-1;
            appendText(i + " bottles of beer on the wall, " + i + " bottles " +
                       "of beer. Take one down, pass it around, " + j + " ");
            if (j != 1) appendText("bottles"); else appendText("bottle");
            appendText(" of beer on the wall.\n");
        }
        appendText("1 bottle of beer on the wall, 1 bottle of beer. Take one " +
                   "down, pass it around, no more bottles of beer on the wall.");
        appendText("No more bottles of beer on the wall, no more bottles of beer. " + 
                   "Go to the store and buy some more, 99 bottles of beer on the wall.");
            
    }       
    
}

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: