Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A class to describe the measurements in feet and inches.
- *
- * @author
- * @version 10/14/13
- */
- public class Measurement implements Comparable<Measurement>
- {
- private double woodSize;
- private int woodFeet;
- private double woodInches;
- /**
- * Constructor for a measurement.
- * @param feet The feet of the piece of wood.
- * @param inches The inches of the piece of wood, in the form
- * double for precise measurements.
- */
- public Measurement(int feet, double inches)
- {
- woodFeet = feet;
- woodInches = inches;
- woodSize = convert(feet,inches);
- }
- /**
- * Converts the feet and inches measurements into a useable double form.
- * @param feet The feet of the piece of wood.
- * @param inches The inches of the piece of wood.
- * @return the converted measurement.
- */
- private double convert(int feet, double inches)
- {
- double decimal = inches/12;
- decimal += feet;
- return decimal;
- }
- /**
- * Acessor method for getting the converted wood size.
- * returns The converted wood size
- */
- public double getWoodSize()
- {
- return woodSize;
- }
- /**
- * Comparing method used in another class to sort the list.
- * @param other The other measurement you are comparing.
- * @return Returns 1,0,-1 if it is greater, equal, or less than, respectively.
- */
- public int compareTo(Measurement other)
- {
- int result = 0;
- if (getWoodSize() > other.getWoodSize())
- {
- result = 1;
- }
- else if (getWoodSize() < other.getWoodSize())
- {
- result = -1;
- }
- else
- {
- }
- return result;
- }
- /**
- * The string representation of a measurement.
- * @return Returns the string of the measurement.
- */
- public String toString()
- {
- return woodFeet + "' " + woodInches + "''";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement