Write the following function in Java:
A function "makeMangler", that takes as input a list M of three numbers. It then builds and returns a "Mangler" function based on M. The "Mangler" function that is produced (by your function makeMangler) would have the property that it takes as input a list, and returns the "mangled" version of that list. "Mangling" a list means doing the following sequence of operations to each item in a list: (1) multiply by the first element in M, then (2) add the second element in M, then (3) multiply by the third element in M. For example, if 'makeMangler" was called as follows: (makeMangler '(2 3 8)) a function would be produced that takes as input a list and returns the "mangled" version, based on the list '(2 3 8). For example, if the original call had been made as follows: (define C (makeMangler '(2 3 8))) then the produced function C would behave as follows: (C '(4 8 2 9)) *** would return (88 152 56 168) (C '(-2 3)) *** would return (-8 72) Your task is just to write makeMangler, not "C". Of course, makeMangler should work for ANY input list, not just (2 3 8).
According to my deductions from the question the following code snippet should work. Not implementing C() fully just for test purpose.
makeMangler method of class Mangle takes 3 inputs and sets the class variables and returns a type interface.
//Mangler.java
package com.test;
public interface Mangler {
//Tester Class
void C1(int i, int j, int k, int l);
}
------------------------------------------------------------------------------------------------------------------
//Mangle.java
package com.test;
public class Mangle implements Mangler {
int num1;
int num2;
int num3;
//makeMangler takes 3 inputs returns interface
Mangler
public Mangler makeMangler(int a, int b, int c)
{
Mangle setValues = new
Mangle();
setValues.num1 = a;
setValues.num2 = b;
setValues.num3 = c;
return setValues;
}
@Override
//Tester class
public void C1(int i, int j, int k, int l) {
// TODO Auto-generated method
stub
int temp = i * num1;
int temp2 = temp + num2;
temp = temp2 * num3;
System.out.println("Output C1 is "
+ temp); //calculated just for one
}
public static void main(String[] args) {
Mangle a = new Mangle(); //get
class object
Mangler m = a.makeMangler(2,3,8);
//calling make mangler returning interface Mangler
m.C1(4,8,2,9);
}
}
Write the following function in Java: A function "makeMangler", that takes as input a list M...
Write the function deep_contains. It takes as input a number and a list. That list might contain lists as elements, and those lists might contain lists, etc. The deep_contains' function should return a Boolean indicating whether the number is contained inputted list, or a sublist of it, or a sublist of that, and so forth. For example: deep_contains (3, (1,3,5]) returns True deep_contains(3, 11, [3,5]]) returns True deep_contains (3, 1, [[3,4],5),6]) returns True deep_contains (2, (1,3,5]) returns False This function...
Write a Scheme function DEL-LELEMENT that takes a list as a parameter and returns a list identical to the parameter except the last element has been deleted. For example, (DEL-LELEMENT '(8 2 3 7 6)) should return (8 2 3 7) *Please explain your code and submit the source code. Please test the function with the provided example and submit a screen shot of the testing result.
JAVA - Write a recursive function that takes a linked list as input and returns all of the elements in the linked list. Input: 1, 2, 3, 4, 5 Output: (1+2+3+4+5)/5 = 3 What I have: public static int findMean (Node head, Node cur, int n){ int average = 0; if (head == null){ if(n == 0) return 0; } if (n > 0){ int sum = n + findMean(head, head.next, n -1); average = (sum)/n; } return average; }...
Write a python function that takes a string as input, and returns a dictionary of frequencies of all the characters in the string. For example: freq("dabcabcdbbcd") would return {"d":3, "a":2, "b":4, "c":3}. Then write a driver to demonstrate your function.
Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...
Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...
Write a function which takes a list and returns frequencies of each element in the list? For example: L=[‘a’,’b’,’a’,’c’,’d’,’b’] Returns ‘a’: 2, ‘b’: 2, ‘c’: 1, ‘d’: 1
Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python
Write a function rm_multiple() that takes two parameters as input (a list of strings, and a list of strings to remove from the list) and returns a new list with the items removed. # Define function in this cell def rm_multiple(strings,remove_list): l = [10,20,40,50] #use to delete an element in the list for string in strings: strings= l if string not in remove_list: lst.append(string) # Edit the code here to call your function in this cell items = [10,20,40,50] to_remove...
Please I need help with this. Thank you Write the function cycle of type 'a list *int-> 'a list that takes a list and an integer n as input and returns the same list, but with the first element cycled to the end of the list n times. For example, cycle ([1,2,3,4,5,6], 2) should return [3,4,5,6,1,2)]. You can make use of the cycle 1 function given below as a helper function. fun cycle1 list- tl list hd list]: