Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java/Android Programming: Adapter Design Pattern I am given the classes below. N

ID: 3830602 • Letter: J

Question

Java/Android Programming: Adapter Design Pattern

I am given the classes below. Note: Code developed in Android Studio environment. It does not make use of Android characteristics--except that it makes calls to Log.i() rather than System.out.println(). I need help implementing an adapter class called NewNodeAdapter so that the app displays relationships between paired nodes according to the sample output shown below. By creating the adapter class, the app gives results while using a base class which stores its ID as a String rather than as an int. It's not necessary to change the use or implementation of showWhatImPairedWith() because the app just puts in integer ID values anyway, and doesn't expect to find ID's in nodes which are Strings which do not contain valid sequences of integer digits.


class NewNodeClass
{
    private String nodeString;
    private ArrayList<NewNodeClass> whatImPairedWith;

    public NewNodeClass(String nodeStringIn)
    {
        nodeString = nodeStringIn;
        whatImPairedWith = new ArrayList<NewNodeClass>();
    }

    public void setNodeString(String nodeStringIn)
    {
        nodeString = nodeStringIn;
    }

    public String getNodeString()
    {
        return nodeString;
    }

    public void pairMeWith(NewNodeClass mateIn)
    {
        whatImPairedWith.add(mateIn);
    }

    public ArrayList<NewNodeClass> getWhatImPairedWith()
    {
        return whatImPairedWith;
    }

    public void showWhatImPairedWith() {
        for(NewNodeClass aNode: whatImPairedWith)
        {
            Log.i("Node ", aNode.getNodeString() + "");
        }
    }
}

interface NewNodeInterface
{
    void setNodeID(int nodeIDIn);
    int getNodeID();
}

Sample Output

.../.../Node: 0 is paired with

.../.../Node: 1

.../.../Node: 9

.../.../Node: 1 is paired with

.../.../Node: 0

.../.../Node: 2

.../.../Node: 2 is paired with

.../.../Node: 1

.../.../Node: 3

.../.../Node: 3 is paired with

.../.../Node: 2

.../.../Node: 4

.../.../Node: 4 is paired with

.../.../Node: 3

.../.../Node: 5

.../.../Node: 5 is paired with

.../.../Node: 4

.../.../Node: 6

.../.../Node: 6 is paired with

.../.../Node: 5

.../.../Node: 7

.../.../Node: 7 is paired with

.../.../Node: 6

.../.../Node: 8

.../.../Node: 8 is paired with

.../.../Node: 7

.../.../Node: 9

.../.../Node: 9 is paired with

.../.../Node: 8

.../.../Node: 0

Explanation / Answer

As far as specs are concerned the below-given class should do its job fairly well. If you think the class definition I considered is not what the question intended, let me know.

class NewNodeAdapter extends NewNodeClass{

    int nodeId;
    public NewNodeAdapter(int nodeStringIn) {
        super("Node " + nodeStringIn);
        nodeId = nodeStringIn;
    }
    public int getNodeID(){
        return nodeId;
    }
}

I tried my best to keep the code short and remove all useless code segments. As I mentioned earlier, the given glass complies with all your requirements stated. If you have any doubt, please let me know. I shall be glad to help you :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote