clanecollege

Bicycle.java

May 16th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. public class Bicycle
  2. {
  3.     // member variables
  4.     int pedalRate;
  5.     int speed;
  6.     int gear;
  7.  
  8.     // constructor for class without parameters
  9.     public Bicycle()
  10.     {
  11.         this.pedalRate = 1;
  12.         this.speed = 10;
  13.         this.gear = 0;
  14.     }
  15.  
  16.     // constructor for class with parameters
  17.     public Bicycle(int pR, int sP, int g)
  18.     {
  19.         this.pedalRate = pR;
  20.         this.speed = sP;
  21.         this.gear = g;
  22.     }
  23.  
  24.     public void changePedalRate(int newValue)
  25.     {
  26.         pedalRate = newValue;
  27.     }
  28.  
  29.     public void changeGear(int newValue)
  30.     {
  31.         gear = newValue;
  32.     }
  33.  
  34.     public void speedUp(int increment)
  35.     {
  36.         speed += increment;
  37.     }
  38.  
  39.     public void applyBrakes(int decrement)
  40.     {
  41.         speed -= decrement;
  42.     }
  43.  
  44.     public void printStates()
  45.     {
  46.         System.out.println("pedalRate: " + pedalRate + "\nspeed: " + speed
  47.                 + "\ngear: " + gear);
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment