/* SimpleExample/Bug.java A very simple class, with two fields: ID weight */ public class Bug { // instance variables int ID; // these have the default access double weight; // "package private" // constructors -- with different parameters required Bug () { // create with defaults provided ID = 0; weight = 0.0; } Bug ( int id ) { // requires an id paramter ID = id; weight = 0.0; } Bug ( int id, double wt ) { // required id and weight parameters ID = id; weight = wt; } public void sayHello () { System.out.printf( "Bug with ID = %d, weight = %.2f says 'Hello'!\n", ID, weight ); } public void sayHelloTo ( Bug otherBug ) { System.out.printf( "Bug %d says 'Ciao' to otherBug %d!\n", ID, otherBug.getID() ); } ///////////////////////////////////////////////////////////////////////////////// // accessors (getters/setters) public int getID () { return ID; } public void setID ( int id ) { ID = id; } public double getWeight () { return weight; } public void setWeight ( double wt ) { weight = wt; } }