1. public class Bicycle {
  2.  
  3. // the Bicycle class has three fields
  4. public int cadence;
  5. public int gear;
  6. public int speed;
  7.  
  8. // the Bicycle class has one constructor
  9. public Bicycle(int startCadence, int startSpeed, int startGear) {
  10. gear = startGear;
  11. cadence = startCadence;
  12. speed = startSpeed;
  13. }
  14.  
  15. // the Bicycle class has four methods
  16. public void setCadence(int newValue) {
  17. cadence = newValue;
  18. }
  19.  
  20. public void setGear(int newValue) {
  21. gear = newValue;
  22. }
  23.  
  24. public void applyBrake(int decrement) {
  25. speed -= decrement;
  26. }
  27.  
  28. public void speedUp(int increment) {
  29. speed += increment;
  30. }
  31.  
  32. }
  33.  
  34. public class MountainBike extends Bicycle {
  35.  
  36. // the MountainBike subclass has one field
  37. public int seatHeight;
  38.  
  39. // the MountainBike subclass has one constructor
  40. public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {
  41. super(startCadence, startSpeed, startGear);
  42. seatHeight = startHeight;
  43. }
  44.  
  45. // the MountainBike subclass has one method
  46. public void setHeight(int newValue) {
  47. seatHeight = newValue;
  48. }
  49.  
  50. }
  51.