// Example put together during lecture class. Feel free to add to this, // or try out changes, other methods, etc. class Length { private int feet; // 0 or more private double inches; // 0 <= inches < 12.0 // default constructor: init to 0' 0" public Length() { this(0,0); } public Length(int f, double i) { if (set(f,i) == false) // if set attempt doesn't work set(0,0); } public boolean set(int f, double i) { if (f >= 0 && i >= 0 && i < 12) { feet = f; inches = i; return true; } else return false; } public int getFeet() { return feet; } public double getInches() { return inches; } public String toString() { return (feet + "\' " + inches + "\""); } public Length add(Length rSide) { int f = feet + rSide.feet; // add together the two feet double i = inches + rSide.inches; if (i >= 12) { f++; // add one foot i -= 12; // subtract 12 from inches } return new Length(f,i); } public static void main(String[] args) { Length L1 = new Length(); // use default constructor Length L2 = new Length(3, 6.5); // 3' 6.5" System.out.println("L1 = " + L1); System.out.println("L2 = " + L2); L1.set(5,10.4); L2.set(-4,11); System.out.println("L1 = " + L1); System.out.println("L2 = " + L2); Length result; result = L1.add(L2); // desired call System.out.println("L1.add(L2) returns " + result); } }