Guest User

Untitled

a guest
Jan 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. //from the book "Practical Object-Oriented Design in Ruby" by Sandi Metz
  2. namespace POODR_Example
  3. {
  4. public class Gear
  5. {
  6. private int chainring, cog, rim; //data fields
  7. private double tire;
  8.  
  9. public Gear (int chainring, int cog, int rim, double tire) //constructor
  10. {
  11. this.chainring = chainring;
  12. this.cog = cog;
  13. this.rim = rim;
  14. this.tire = tire;
  15. }
  16.  
  17. public int GetGearInches () //public accessor method
  18. {
  19. return GetRatio() * new Wheel(rim, tire).GetDiameter();
  20. }
  21.  
  22. private int GetRatio () //private helper method
  23. {
  24. return chainring / cog;
  25. }
  26. }
  27.  
  28. public class Wheel
  29. {
  30. private int rim; //data fields
  31. private double tire;
  32.  
  33. public Wheel (int rim, double tire) //constructor
  34. {
  35. this.rim = rim;
  36. this.tire = tire;
  37. }
  38.  
  39. public int GetDiameter () //public accessor method
  40. {
  41. return rim * (int)(tire * 2);
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment