Can someone help me with this?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Can someone help me with this? 

 

code:

public class ArrayListFun {

/**
* Counts the number of instances of a particular value in list.
* Returns null if list is null.
*
* @param list
* @param checkNum
* @return the number of Integer occurrences in list equal to checkNum
*/
public static Integer countOccurrences(ArrayList<Integer> list, int checkNum) {
// TODO: FILL IN BODY
return null;
}

/**
* Calculates the sum, product, or mean of all values in list.
* Returns null if list is null.
*
* @param list
* @param operation
* @return the sum, product, or mean of all values in list
*/
public static Integer mathOperation(ArrayList<Integer> list, String operation) {
// TODO: FILL IN BODY
return null;
}

/**
* Converts the 1s and 0s in list (binary value) to its decimal value
*
* Example: 100110 from binary to decimal
*
* 1 * 2^5 +
* 0 * 2^4 +
* 0 * 2^3 +
* 1 * 2^2 +
* 1 * 2^1 +
* 0 * 2^0 =
* 38
*
* For more information on binary, see zyBooks chapter 3.1
*
* Returns null if list is null.
*
* @param list
* @return the decimal value of the binary representation of list
*/
public static Integer binaryToDecimal(ArrayList<Integer> list) {
// TODO: FILL IN BODY
return null;
}

/**
* Returns true if list is a (character) palindrome.
* Returns null if list is null.
*
* @param list
* @return true if the list is a palindrome, else false.
*/
public static Boolean isPalindrome(ArrayList<Character> list) {
// TODO: FILL IN BODY
return null;
}

public static void main(String[] args) {
// TODO: FILL IN BODY
}
}

Example method arguments:
[2, 0, 5, 2, 2, 1, 1] and operation
// list
// list
"add"
[2, 0, 5, 2, 2, 1, 1] and operation
"multiply"
// list
[2, 0, 5, 2, 2, 1, 1] and operation
"mean"
Example method return values:
13
1
3. (binaryToDecimal) Covert an ArrayList containing only Os and 1s to its corresponding decimal value (index 0 of the ArrayList being the
leftmost bit)
Iterate through each value in list. Add (list value)*(2^j) to a running sum variable. Here 'j' is the index opposite of conventional Java
indexing (ie 0 index is the furthest right index, and length-1 is the furthest left index). Further information on converting from binary to
decimal can be found in zyBooks Table 2.1.2.
• Return the running sum value. However, if list is null, return null.
Example method arguments:
// list
[1, 0, 0, 1,
[1, 0, 0, 1, 1, 1]
1]
// list
Example method return values:
19
39
4. (isPalindrome) Implement a palindrome checker Note: a palindrome is a word or phrase that is spelled the same forwards as it is
Transcribed Image Text:Example method arguments: [2, 0, 5, 2, 2, 1, 1] and operation // list // list "add" [2, 0, 5, 2, 2, 1, 1] and operation "multiply" // list [2, 0, 5, 2, 2, 1, 1] and operation "mean" Example method return values: 13 1 3. (binaryToDecimal) Covert an ArrayList containing only Os and 1s to its corresponding decimal value (index 0 of the ArrayList being the leftmost bit) Iterate through each value in list. Add (list value)*(2^j) to a running sum variable. Here 'j' is the index opposite of conventional Java indexing (ie 0 index is the furthest right index, and length-1 is the furthest left index). Further information on converting from binary to decimal can be found in zyBooks Table 2.1.2. • Return the running sum value. However, if list is null, return null. Example method arguments: // list [1, 0, 0, 1, [1, 0, 0, 1, 1, 1] 1] // list Example method return values: 19 39 4. (isPalindrome) Implement a palindrome checker Note: a palindrome is a word or phrase that is spelled the same forwards as it is
9.11 ***zyLab: ArrayList Fun
The goal of this program is to practice performing some common programming operations using only 1-dimensional ArrayLists.
You will write four methods, each of which perform some operation on an ArrayList. Each method is described below. In main, you will call
your four methods using the provided arguments.
1. (countOccurrences) Count the number of instances of a particular value in an ArrayList
• Iterate through each value in list, incrementing a running sum variable by one for every instance equal to checkNum in list.
• Return the running sum. However, if list is null, return null.
Example method arguments:
[2, 0, 5, 2, 2, 1, 1] and checkNum
[2, 0, 5, 2, 2, 1, 1] and checkNum
// list
2
%3D
// list
3
||
Example method return value:
3
2. (mathOperation) Perform one of three math operations (add, multiply, or mean) on an ArrayList
• Iterate through each value in list.
If operation equals "add", then every iteration of list will add the value at that particular index in list to a running sum variable.
• If operation equals "multiply", then every iteration of list will multiply the value at that particular index in list to a running product
variable.
If operation equals "mean", then every iteration of list will add the value at that particular index in list to a running sum variable. After
iterating through the list, divide that running sum by the number of elements in list. Note that because this method returns an Integer,
the mean may be truncated.
Transcribed Image Text:9.11 ***zyLab: ArrayList Fun The goal of this program is to practice performing some common programming operations using only 1-dimensional ArrayLists. You will write four methods, each of which perform some operation on an ArrayList. Each method is described below. In main, you will call your four methods using the provided arguments. 1. (countOccurrences) Count the number of instances of a particular value in an ArrayList • Iterate through each value in list, incrementing a running sum variable by one for every instance equal to checkNum in list. • Return the running sum. However, if list is null, return null. Example method arguments: [2, 0, 5, 2, 2, 1, 1] and checkNum [2, 0, 5, 2, 2, 1, 1] and checkNum // list 2 %3D // list 3 || Example method return value: 3 2. (mathOperation) Perform one of three math operations (add, multiply, or mean) on an ArrayList • Iterate through each value in list. If operation equals "add", then every iteration of list will add the value at that particular index in list to a running sum variable. • If operation equals "multiply", then every iteration of list will multiply the value at that particular index in list to a running product variable. If operation equals "mean", then every iteration of list will add the value at that particular index in list to a running sum variable. After iterating through the list, divide that running sum by the number of elements in list. Note that because this method returns an Integer, the mean may be truncated.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY