/** * This is an example of a Java object, written for Jim's * introduction to programming class. * * @author Jim Mahoney * @version 1.0, Sep 17 2002 */ // The javadoc documentation was processed with the following commands: // mkdir JimsCar-docs // javadoc JimsCar.java -d JimsCar-docs // Then just point your browser at JimsCar-docs public class JimsCar { private String itsColor; // an "instance variable" (data) /** * This constructor creates a JimsCar object. * * @param color the color of the car */ public JimsCar(String color) { // Constructor - creates a JimsCar setColor(color); } /** * Create a black JimsCar object. (No argument passed.) */ public JimsCar() { itsColor = "Black"; } /** * Returns the color of the car. * @return the color of the car */ public String getColor(){ return itsColor; } /** * Sets the color of the car. * @param color What color would you like it to be? */ public void setColor(String color){ itsColor=color; } /** * Move the car forward. * (If this were a real car - or lego robot - then * this method might do more than just print to the screen.) */ public void goForward(){ System.out.println(" The " + getColor() + " car is going forward."); } }