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

Lists are one of the most fundamental of the data types. Your ability to underst

ID: 673781 • Letter: L

Question

Lists are one of the most fundamental of the data types. Your ability to understand lists as an Abstract Data Type (ADT) and implement lists is key to your understanding of all the more complex data structures. In this module you should first completely review Topic - Basic Data structures which covers lists. Once complete you should be ready to tackle some of the challenging assignments available in this module.

In Javascript we are going to create a Class called Chain. If you need a little primer on creating objects and classes in Javascript see http://www.w3schools.com/js/js_object_definition.asp - if you know your object oriented code this will be relatively straightforward. Your Chain will be made up of Links. Each link will have an id, a value (String) and a pointer to the next link ( NextLink ) - which is simply a pointer to the id of the next link in the Chain. Please note that this is a very inefficient representation of the Chain. Here is a simple Javascript code definition of a Link for you to use.https://jsfiddle.net/reaglin/q46obht6/

You will make a Chain consisting of 5 links. You will also create a print function for the chain that will print the links in link order. You may need to create some functions to support this functionality. Please include screenshots and / or temples of the Javascipt code in JSFiddle. Thank you!

Explanation / Answer

abstract class Chain
{
public static int> public static int Two = 2;
public static int Three = 3;
protected int Threshold;
protected Chain next;
public void setNext(Chain chain)
{
next = chain;
}
public void message(String msg, int priority)
{
if (priority <= Threshold)
{
writeMessage(msg);
}
if (next != null)
{
next.message(msg, priority);
}
}
abstract protected void writeMessage(String msg);
}
class A extends Chain
{
public A(int threshold)
{
this.Threshold = threshold;
}
protected void writeMessage(String msg)
{
System.out.println("A: " + msg);
}
}
class B extends Chain
{
public B(int threshold)
{
this.Threshold = threshold;
}
protected void writeMessage(String msg)
{
System.out.println("B: " + msg);
}
}
class C extends Chain
{
public C(int threshold)
{
this.Threshold = threshold;
}
protected void writeMessage(String msg)
{
System.out.println("C: " + msg);
}
}
public class ChainOfResponsibilityExample
{
private static Chain createChain()
{
Chain chain1 = new A(Chain.Three);
Chain chain2 = new B(Chain.Two);
chain1.setNext(chain2);
Chain chain3 = new C(Chain.One);
chain2.setNext(chain3);
return chain1;
}
public static void main(String[] args)
{
Chain chain = createChain();
chain.message("level 3", Chain.Three);
chain.message("level 2", Chain.Two);
chain.message("level 1", Chain.One);
}
}

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