***Code to solve***
package functions;
import java.math.*; // for BigInteger
public class NodeTransitionFunction {
public NodeTransitionFunction(Integer exp, Integer
KVal) {
// CONSTUCTOR: Sets the class to
calculate f(x) = (x ^ exp) mod KVal
// TODO
}
public Integer apply(Integer val) {
// PRE: -
// POST: Implements f(val)
return null;
}
public BigInteger apply(BigInteger val) {
// PRE: -
// POST: Implements f(val), with
val as a BigInteger
// TODO
return null;
}
public static void main(String[] args) {
NodeTransitionFunction f = new
NodeTransitionFunction(3, 33);
System.out.println(f.apply(5));
}
}
package functions; import java.math.*; // for BigInteger public class NodeTransitionFunction { private Integer exp; private Integer KVal; public NodeTransitionFunction(Integer exp, Integer KVal) { // CONSTRUCTOR: Sets the class to calculate f(x) = (x ^ exp) mod KVal this.exp = exp; this.KVal = KVal; } public Integer apply(Integer val) { Integer result = 1; for (int i = 0; i < exp; i++) { result *= val % KVal; } return result % KVal; } public BigInteger apply(BigInteger val) { BigInteger result = BigInteger.valueOf(1); for (int i = 0; i < exp; i++) { result = result.multiply(val); } return result.mod(BigInteger.valueOf(KVal)); } public static void main(String[] args) { NodeTransitionFunction f = new NodeTransitionFunction(3, 33); System.out.println(f.apply(5)); } }
***Code to solve*** package functions; import java.math.*; // for BigInteger public class NodeTransitionFunction { public...
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...
//MultiValuedTreeMap.java import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; //import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>> implements Iterable<Pair<K, V>> { private static final long serialVersionUID = -6229569372944782075L; public void add(K k, V v) { // Problem 1 method // empty linked list, with key=k if (!containsKey(k)) { put(k, new LinkedList<V>()); } // adding v to the linked list associated with key k get(k).add(v); } public V removeFirst(K k)...
Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA { private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...
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....
ANNOTATE BRIEFLY LINE BY LINE THE FOLLOWING CODE: package shop.data; import junit.framework.Assert; import junit.framework.TestCase; public class DataTEST extends TestCase { public DataTEST(String name) { super(name); } public void testConstructorAndAttributes() { String title1 = "XX"; String director1 = "XY"; String title2 = " XX "; String director2 = " XY "; int year = 2002; Video v1 = Data.newVideo(title1, year, director1); Assert.assertSame(title1, v1.title()); Assert.assertEquals(year, v1.year()); Assert.assertSame(director1, v1.director()); Video v2 = Data.newVideo(title2, year, director2); Assert.assertEquals(title1, v2.title()); Assert.assertEquals(director1, v2.director()); } public void testConstructorExceptionYear()...
I need some help with some homework questions. How would I implement the to-do's? ----------------------------------------------------------------------------------------------------------------------------------------------------------- AbstractArrayHeap.Java package structures; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; public abstract class AbstractArrayHeap<P, V> { protected final ArrayList<Entry<P, V>> heap; protected final Comparator<P> comparator; protected AbstractArrayHeap(Comparator<P> comparator) { if (comparator == null) { throw new NullPointerException(); } this.comparator = comparator; heap = new ArrayList<Entry<P, V>>(); } public final AbstractArrayHeap<P, V> add(P priority, V value) { if (priority == null || value...
import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>> implements Iterable<Pair<K, V>> { private static final long serialVersionUID = -6229569372944782075L; public void add(K k, V v) { if (!containsKey(k)) { put(k, new LinkedList<V>()); } get(k).add(v); } public V removeFirst(K k) { if (!containsKey(k)) { return null; } V value = get(k).removeFirst(); if (get(k).isEmpty()) { super.remove(k); } return value; }...
P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList() { header = null; } public final Node Search(int key) { Node current = header; while (current != null && current.item != key) { current = current.link; } return current; } public final void Append(int newItem) { Node newNode = new Node(newItem); newNode.link = header; header = newNode; } public final Node Remove() { Node x = header; if (header != null) { header...
JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet { /** * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList * containing all the indexes of Strings in arr that match String s. For this method, two Strings, * p and q, match when p.equals(q) returns true or if both of the compared references are null. * * @param s The string...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...