Question

I need help to write a code for these conditions public void receiveMsgFromNode(String msg, Integer id,...

I need help to write a code for these conditions

public void receiveMsgFromNode(String msg, Integer id, Integer r, NodeTransitionFunction f) {

// PRE: msg is a message,

// id is the ID of the sending node,

// r is the current value of r from the forward transition function,

// f is the forward transition function

// POST: If this is the destination node, stop;

// otherwise, send the message onwards.

// Add ID of current (receiving) node to local MessageTrackCheck

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

public void receiveMsgFromNode(String msg, Integer id, Integer r, NodeTransitionFunction f) {
// PRE: msg is a message,
// id is the ID of the sending node,
// r is the current value of r from the forward transition function,
// f is the forward transition function
// POST: If this is the destination node, stop;
// otherwise, send the message onwards.
// Add ID of current (receiving) node to local MessageTrackCheck
if (!n.equals(r)) { // if this node is not the same node as sender node
Integer nextId = f.apply(r);
sendMsgToNode((Node)m.get(nextId), msg, nextId, f);
t.add(id);
}
}

Thank You

Add a comment
Know the answer?
Add Answer to:
I need help to write a code for these conditions public void receiveMsgFromNode(String msg, Integer id,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5. There are several getter methods for class Node: public Integer getIDO //PRE:- // POST: Returns node ID public Integ...

    5. There are several getter methods for class Node: public Integer getIDO //PRE:- // POST: Returns node ID public Integer getEO /7PRE //POST: Returns value of e in this node's function f) public Integer getkO /PRE: //POST: Returns value of K in this node's function f) public Boolean transmittedMessage) 7PRE:- /POST: Returns true if this node has transmitted a message, false otherwise public String getMsg) /PRE: // POST: Returns the current received (non-augmented) message, null if no received message 5....

  • 2. Write the following methods for the NodeTransitionFunction class. public NodeTransitionFunction (Integer exp, Intege...

    2. Write the following methods for the NodeTransitionFunction class. public NodeTransitionFunction (Integer exp, Integer KVal) 1t // CONSTUCTOR: Sets the class to calculate f (x) = (x ^ exp) mod KVal public Integer apply (Integer val) // PRE: //POST Implements f (val) Note that if you implement apply) in a straightforward way, you will almost certainly exceed Java's Integer.MAX_VALUE: try it for yourself with an instance of NodeTransitionFunction instantiated with values 3 and 33, comparing it against the value obtained...

  • This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process...

    This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing.  This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...

  • Please create a class in Java that completes the following conditions MorseTree.java /* This program will...

    Please create a class in Java that completes the following conditions MorseTree.java /* This program will read in letters followed by their morse code * and insert them properly in a tree based on the amount of symbols * it has and whether they are left or right descendent. Finally * it prints a few certain nodes. */ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class MorseTree {    public static void main(String[] args) throws FileNotFoundException {        //...

  • Hello, i need help with this homework: Code provided: public class DirectedWeightedExampleSlide18 { public static void...

    Hello, i need help with this homework: Code provided: public class DirectedWeightedExampleSlide18 { public static void main(String[] args) { int currentVertex, userChoice; Scanner input = new Scanner(System.in); // create graph using your WeightedGraph based on author's Graph WeightedGraph myGraph = new WeightedGraph(4); // add labels myGraph.setLabel(0,"Spot zero"); myGraph.setLabel(1,"Spot one"); myGraph.setLabel(2,"Spot two"); myGraph.setLabel(3,"Spot three"); // Add each edge (this directed Graph has 5 edges, // so we add 5 edges) myGraph.addEdge(0,2,9); myGraph.addEdge(1,0,7); myGraph.addEdge(2,3,12); myGraph.addEdge(3,0,15); myGraph.addEdge(3,1,6); // let's pretend we are on...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String a...

    Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String argument. The method will return a new String by removing the logest segment that contains consequtively repeating characters. public static void main(String []args){ String s=”1111222223333311111111444455552222”; String res= removeLongestRepeatingSegment(s); will return “11112222233333444455552222” } public static String removeLongestRepeatingSegment(String s){ --------------- Q2)15p)Given a list of objects stored (in ascending order) in a sorted linked list, implement member method which performs search as efficiently as possible for an object based on a key....

  • I need help with this Mammal: public class Mammal extends Pet{     String Vaccin...

    I need help with this Mammal: public class Mammal extends Pet{     String Vaccination="";     public Mammal(String name, String parent, String species, String birthday, String Vaccination) {           //Accessing the super class Constructor and setting the variables.         super(name,parent,species, birthday);         this.Vaccination=Vaccination;     } // end Mammal     public String getVaccination() {         return Vaccination;     } // end getVaccination     public void setVaccination(String Vaccination) {         this.Vaccination = Vaccination;     } // end setVaccination     @Override     public String toString() {         return super.toString()+". This Mammal requires following vaccinations "+ Vaccination;     } // end...

  • I need help with this project: Code provided: HOUSEGRAPH.java public class HouseGraph extends LinkedGraph { //...

    I need help with this project: Code provided: HOUSEGRAPH.java public class HouseGraph extends LinkedGraph { // establish rooms private final Location kitchen = new Location("Kitchen"); private final Location pantry = new Location("Pantry"); private final Location diningRoom = new Location("Dining Room"); private final Location backFoyer = new Location("Back Foyer"); private final Location frontFoyer = new Location("Front Foyer"); private final Location study = new Location("Study"); private final Location livingRoom = new Location("Living Room"); private final Location stairs = new Location("Stairs"); private final...

  • How can I get started in this program for this DelivC?

    SpecificationStart with your Java program "prog340" which implements Deliverables A and B.This assignment is based on the definition of the Traveling Salesperson Problem (the TSP): Given a set of cities, you want to find the shortest route that visits every city and ends up back at the original starting city. For the purposes of this problem, every city will be directly reachable from every other city (think flying from city to city).Your goal is to use a non-genetic local search...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT