Jay_

Example Java class

Jan 13th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. public class Bicycle {
  2.        
  3.     // the Bicycle class has
  4.     // three fields
  5.     public int cadence;
  6.     public int gear;
  7.     public int speed;
  8.        
  9.     // the Bicycle class has
  10.     // one constructor
  11.     public Bicycle(int startCadence, int startSpeed, int startGear) {
  12.         gear = startGear;
  13.         cadence = startCadence;
  14.         speed = startSpeed;
  15.     }
  16.        
  17.     // the Bicycle class has
  18.     // four methods
  19.     public void setCadence(int newValue) {
  20.         cadence = newValue;
  21.     }
  22.        
  23.     public void setGear(int newValue) {
  24.         gear = newValue;
  25.     }
  26.        
  27.     public void applyBrake(int decrement) {
  28.         speed -= decrement;
  29.     }
  30.        
  31.     public void speedUp(int increment) {
  32.         speed += increment;
  33.     }
  34.        
  35. }
Advertisement
Add Comment
Please, Sign In to add comment