Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. public class Bicycle {
  2.     // the Bicycle class has three fields
  3.  
  4.     public int cadence;
  5.  
  6.     public int gear;
  7.  
  8.     public int speed;
  9.  
  10.     // the Bicycle class has one constructor
  11.  
  12.     public Bicycle(int startCadence, int startSpeed, int startGear) {
  13.  
  14.         gear = startGear;
  15.  
  16.         cadence = startCadence;
  17.  
  18.         speed = startSpeed;
  19.  
  20.     }
  21.  
  22.  
  23.  
  24.     // the Bicycle class has four methods
  25.  
  26.     public void setCadence(int newValue) {
  27.  
  28.         cadence = newValue;
  29.  
  30.     }
  31.  
  32.     public void setGear(int newValue) {
  33.  
  34.         gear = newValue;
  35.  
  36.     }
  37.  
  38.     public void applyBrake(int decrement) {
  39.  
  40.         speed -= decrement;
  41.  
  42.     }
  43.  
  44.     public void speedUp(int increment) {
  45.  
  46.         speed += increment;
  47.  
  48.     }
  49.  
  50.  
  51.  
  52.     public void printDescription(){
  53.  
  54.         System.out.println("\nBike is " + "in gear " + this.gear
  55.  
  56.                 + " with a cadence of " + this.cadence +
  57.  
  58.                 " and travelling at a speed of " + this.speed + ". ");
  59.  
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement