Please help in JAVA: Create a doubly-linked list containing nodes with FeetAndIn
ID: 3880459 • Letter: P
Question
Please help in JAVA:
Create a doubly-linked list containing nodes with FeetAndInches objects. Input will be from the keyboard and of the form int int (two ints per line). The first int will be the feet, the second int the number of inches, and the user will enter 0 0 to stop. After you have built your list, print it out forwards and then in reverse. (you should write two different print methods). Insert the nodes into the list sorted.
public class FeetAndInches {
private int feet;
private int inches;
public FeetAndInches ()
{ feet=0;
inches=0;}
public FeetAndInches (int newf, int newi)
{ feet=newf;
inches=newi;}
public void setFeet(int newf)
{feet = newf;}
public void setInches(int newi)
{ inches = newi;}
public int compareTo(FeetAndInches c)
{int thisInches, inches;
thisInches = this.feet*12 + this.inches;
inches = c.feet*12 + c.inches;
if (thisInches < inches)return -1;
else if (thisInches>inches) return 1;
else return 0;
}
public String toString()
{ return this.feet + " feet and " + this.inches + " inches";
}
}//end FeetAndInches class
Explanation / Answer
Thank You.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.