/* SimpleExample/HelloWorldMain.java HelloWorldMain -- Simple class to get program going. In this case, it creates a few Bug instances, and then sends them messages to ask them to emit the traditional "hello". Compile: javac HelloWorldMain.java Bug.java Run: java HelloWorldMain Copy: cp /users/rlr/Courses/530/Src/SimpleExample/*.java yourDir (This will copy some other java files, too.) Note: the default classpath includes "." (the current working directory) so the above commands are able to find the Bug class */ public class HelloWorldMain { // main (static) method: where the program starts! // args[] is an array of command line arguments public static void main ( String args[] ) { Bug aBug0, aBug1, aBug2; // variables to hold address of Bug instances int numberOfBugs = 0; // we'll keep a count of the number of bugs // lets create some bugs, store addresses in variables aBug0 = new Bug(); // use default bug values aBug0.setID( 0 ); // tell it to set its ID to 0 aBug0.setWeight( 1.0 ); ++numberOfBugs; // increment counter of bugs aBug1 = new Bug( 1 ); // supply an id to this constructor aBug1.setWeight( 4.2 ); ++numberOfBugs; aBug2 = new Bug( 2, 8.4 ); // supply an ID and a weight ++numberOfBugs; // send msg to each, to ask them to say hello System.out.printf( "\n\nAsk the %d bugs to say hello:\n", numberOfBugs ); aBug0.sayHello(); aBug1.sayHello(); aBug2.sayHello(); // now ask them to say hello to each other System.out.printf( "\n\nAsk the bugs to say hello to each other.\n" ); aBug0.sayHelloTo( aBug1 ); aBug1.sayHelloTo( aBug2 ); aBug2.sayHelloTo( aBug0 ); System.out.printf( "\nAll done. Ciao.\n\n" ); } }