Advertisement
jdalbey

Measurement

May 19th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1.  
  2. /**
  3. * A class to describe the measurements in feet and inches.
  4. *
  5. * @author
  6. * @version 10/14/13
  7. */
  8. public class Measurement implements Comparable<Measurement>
  9. {
  10. private double woodSize;
  11. private int woodFeet;
  12. private double woodInches;
  13. /**
  14. * Constructor for a measurement.
  15. * @param feet The feet of the piece of wood.
  16. * @param inches The inches of the piece of wood, in the form
  17. * double for precise measurements.
  18. */
  19. public Measurement(int feet, double inches)
  20. {
  21. woodFeet = feet;
  22. woodInches = inches;
  23. woodSize = convert(feet,inches);
  24. }
  25. /**
  26. * Converts the feet and inches measurements into a useable double form.
  27. * @param feet The feet of the piece of wood.
  28. * @param inches The inches of the piece of wood.
  29. * @return the converted measurement.
  30. */
  31. private double convert(int feet, double inches)
  32. {
  33. double decimal = inches/12;
  34. decimal += feet;
  35. return decimal;
  36. }
  37. /**
  38. * Acessor method for getting the converted wood size.
  39. * returns The converted wood size
  40. */
  41.  
  42. public double getWoodSize()
  43. {
  44. return woodSize;
  45. }
  46.  
  47. /**
  48. * Comparing method used in another class to sort the list.
  49. * @param other The other measurement you are comparing.
  50. * @return Returns 1,0,-1 if it is greater, equal, or less than, respectively.
  51. */
  52. public int compareTo(Measurement other)
  53. {
  54. int result = 0;
  55. if (getWoodSize() > other.getWoodSize())
  56. {
  57. result = 1;
  58. }
  59. else if (getWoodSize() < other.getWoodSize())
  60. {
  61. result = -1;
  62. }
  63. else
  64. {
  65. }
  66.  
  67. return result;
  68. }
  69. /**
  70. * The string representation of a measurement.
  71. * @return Returns the string of the measurement.
  72. */
  73. public String toString()
  74. {
  75. return woodFeet + "' " + woodInches + "''";
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement