Ok, the instructor has give explicit instructions to work with this code and make it work. I have most of it working, but I am hung up on the
portion of the code. I am attaching the class below.Code:public void add1 (int param5, int param6) { Distance d2=d2.add (new Distance(param5, param6)); }
please help.Code://********************************************************************************* //Distance.java // //Chapter 4 project //********************************************************************************* public class Distance { private int feet; private int inches; public Distance() { feet = 0; inches = 0; } public Distance(int param1, int param2) { feet = param1; inches = param2; } public Distance(Distance d) { feet = d.getFeet(); inches = d.getInches(); } public int getFeet() { return feet; } public int getInches() { return inches; } public void setFeet(int param3) { feet = param3; } public void setInches(int param4) { inches = param4; } private int toInches() { return feet * 12 + inches; } public void add (Distance distance) { int totalInches = toInches() + distance.toInches(); feet = totalInches / 12; inches = totalInches % 12; } //-------------------------------------------------------------------------- //method takes 2 integer parameters representing a distance in feet and //inches. //-------------------------------------------------------------------------- public void add1 (int param5, int param6) //creates local Distance object & passes it to the other //add method { Distance d2 = d2.add new Distance(param5, param6); //adds parameter's distance to the current //distance ensuring that the result is //correct & that inches is between 0-11 } public String toString() { return feet + "\'" + inches + "\""; } }


Reply With Quote


Bookmarks