更 多...

Blog »Bicycle

 
 
 
2009-12-04 09:29:29 @~^_^ luancgy

public class Bicycle {
   
    // the Bicycle class has three fields
    public int cadence;
    public int gear;
    public int speed;
   
    // the Bicycle class has one constructor
    public Bicycle(int startCadence, int startSpeed, int startGear) {
        gear = startGear;
        cadence = startCadence;
        speed = startSpeed;
    }
   
    // the Bicycle class has four methods
    public void setCadence(int newValue) {
        cadence = newValue;
    }
   
    public void setGear(int newValue) {
        gear = newValue;
    }
   
    public void applyBrake(int decrement) {
        speed -= decrement;
    }
   
    public void speedUp(int increment) {
        speed += increment;
    }
   
}

 
 

登录后您就可以发表回复.