Homework Solution: Please help in JAVA:…

    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

    Expert Answer

     
    BEGINNING OF THE PROGRAM.
    // Class for Doubly Linked List

    Please aid in JAVA:

    Cause a doubly-linked register containing nodes with FeetAndInches objects. Indispose allure be from the keyboard and of the construct int int (span ints per row). The highest int allure be the feet, the prevent int the compute of inches, and the user allure invade 0 0 to plug. Behind you feel built your register, imimstereotype it quenched cewards and then in inversion. (you should transcribe span unanalogous imimstereotype methods). Inoculate the nodes into the register orderly.

    notorious systematize FeetAndInches {

    private int feet;
    private int inches;
    notorious FeetAndInches ()
    { feet=0;
    inches=0;}
    notorious FeetAndInches (int oddf, int oddi)
    { feet=newf;
    inches=newi;}
    notorious lacking setFeet(int oddf)
    {feet = oddf;}
    notorious lacking setInches(int oddi)
    { inches = oddi;}

    notorious int compareTo(FeetAndInches c)
    {int thisInches, inches;
    thisInches = this.feet*12 + this.inches;
    inches = c.feet*12 + c.inches;
    if (thisInches < inches)repay -1;
    else if (thisInches>inches) repay 1;
    else repay 0;
    }
    notorious String toString()
    { repay this.feet + ” feet and ” + this.inches + ” inches”;
    }
    }//object FeetAndInches systematize

    Expert Repartee

     

    BEGINNING OF THE PROGRAM.
    // Systematize ce Doubly Linked Register
    notorious systematize DLL 
    {
            Node source; // source of register
            
            /* Doubly Linked register Node*/
            systematize Node
            {
                    int feet;
                    int inches;
                    Node prev;
                    Node instant;
                    
                    
            // Constructor to cause odd nodes
                    // instant and prev is by absence initialized as vain
                    Node(int f){
                          feet=f;}
                    Node (int i) {
                          inches=i;} 
            }
    
            //Adding a node at the front of the register
            notorious lacking butt(int odd_data)
            {
                    /* 1. place node 
                    * 2. dispose in the feet */
                    Node odd_Node = odd Node(new_feetandinches);
                   
                    
                    /* 3. Mould instant of odd node as source and prior as NULL */
                    odd_Node.instant = source;
                    odd_Node.prev = vain;
                    
                    /* 4. alter prev of source node to odd node */
                    if(source != vain)
                            source.prev = odd_Node;
    
                    /* 5. stir the source to sharp-object to the odd node */
                    source = odd_Node; 
            }
    
            /* Consecrated a node as prev_node, inoculate a odd node behind the consecrated node */
            notorious lacking InoculateAfter(Node prev_Node,int odd_FeetandInches)
            {
                    
                    /*1. repress if the consecrated prev_node is NULL */
                    if(prev_Node == vain)
                    {
                            System.out.println("The consecrated prior node cannot be NULL ");
                            repay;
                    }
                    
                    /* 2. place node 
                    * 3. dispose in the axioms */
                    Node odd_node = odd Node(new_FeetandInches);
                    
                    /* 4. Mould instant of odd node as instant of prev_node */
                    odd_node.instant = prev_Node.next;
                    
    
                    /* 5. Mould the instant of prev_node as odd_node */
                    prev_Node.instant = odd_node;
                    
                    /* 6. Mould prev_node as prior of odd_node */
                    odd_node.prev = prev_Node;
                    
                    /* 7. Alter prior of odd_node's instant node */
                    if(new_node.instant != vain)
                            odd_node.next.prev = odd_node;
            }
            
            //Add a node at the object of the register
            lacking attach(int odd_FeetandInches)
            {
                    /* 1. place node 
                    * 2. dispose in the axioms */
                    Node odd_node = odd Node(new_FeetandInches);
                    
                    Node terminal = source;/* used in tramp 5*/
                    
                    /* 3. This odd node is going to be the terminal node, so
                    * mould instant of it as NULL*/
                    odd_node.instant = vain;
                    
                    /* 4. If the Linked Register is nugatory, then mould the odd
                    * node as source */
                    if(source == vain)
                    {
                            odd_node.prev = vain;
                            source = odd_node;
                            repay;
                    }
                    
                    /* 5. Else thwart tobject the terminal node */
                    suitableness(last.instant != vain)
                            terminal = terminal.next;
                    
                    /* 6. Alter the instant of terminal node */
                    terminal.instant = odd_node;
                    
                    /* 7. Mould terminal node as prior of odd node */
                    odd_node.prev = terminal;
            }
            
            // This administration imprints interruption of linked register starting from the consecrated node
            notorious lacking imprintlist(Node node)
            {
                    Node terminal = vain;
                    System.out.println("Traversal in ceward Direction");
                    suitableness(node != vain)
                    {
                            System.out.print(node.feet + "feet and "+ node.inches +"inches");
                            terminal = node;
                            node = node.next;
                    }
                    System.out.println();
                    System.out.println("Traversal in inversion direction");
                    suitableness (terminal != vain)
                    {
                            System.out.print(last.axioms + " ");
                            terminal = terminal.prev;
                    }
            }
            
            /* Drier program to trial over administrations*/
            notorious static lacking main(String[] args) 
            {
                    /* Start with the nugatory register */
                    DLL dll = odd DLL();
                     
                    // Inoculate 6. So linked register becomes 6->NULL
                    dll.append(6);
                    
                    // Inoculate 7 at the initiation. So linked register becomes 7->6->NULL
                    dll.push(7);
                    
                    // Inoculate 1 at the initiation. So linked register becomes 1->7->6->NULL
                    dll.push(1);
                    
                    // Inoculate 4 at the object. So linked register becomes 1->7->6->4->NULL
                    dll.append(4);
                    
                    // Inoculate 8, behind 7. So linked register becomes 1->7->8->6->4->NULL
                    dll.InsertAfter(dll.head.next, 8);
                    
                    
                    System.out.println("Created DLL is: ");
                    dll.printlist(dll.head);
            }
    }