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

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

ID: 3831096 • Letter: J

Question

Java/Android Programming: Mediator 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 a class called MyMediator with a showPairList() method that displays relationships between paired nodes according to the sample output shown below.

class MyNodeClass
{
    private int nodeID;

    public MyNodeClass(int nodeIDIn)
    {
        nodeID = nodeIDIn;
    }

    public void setNodeID(int nodeIDIn)
    {
        nodeID = nodeIDIn;
    }

    public int getNodeID()
    {
        return nodeID;
    }
}

class MyPair
{
    private MyNodeClass node1;
    private MyNodeClass node2;

    public MyPair(MyNodeClass node1In, MyNodeClass node2In)
    {
        node1 = node1In;
        node2 = node2In;
    }

    public MyNodeClass getNode1()
    {
        return node1;
    }

    public MyNodeClass getNode2()
    {
        return node2;
    }
}

Sample Output:

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

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

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

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

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

...

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

Explanation / Answer

Hi,

Please find the code snippet to display the node pair relationship below:-

CODE:-


class MyMediator
{

MyMediator[] arrayOfMediator1 = new MyMediator[18];
MyMediator[] arrayOfMediator2 = new MyMediator[18];
int i=0;
void addPair(MyNodeClass arrayOfNodes[1],MyNodeClass arrayOfNodes[2])
{
  

arrayOfMediator1[i]=arrayOfNodes[1];
arrayOfMediator2[i]=arrayOfNodes[2];
i++;
}
void showPairList()
{
for (int j=0;j<18;j++)
{
System.out.println("Node"+arrayOfMediator1[j]+"is paired with node"+arrayOfMediator2[j]);

}
}
}

====================================================================================

Please let me know in case of any clarification.

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