ample: ell> var I = new StringI { "hello", "world", "what", "up" } > String[4] { "hello", "world", "what", "up" } ell> rotateRight(1) mell>| » String[4] { "up","hello", "world", "what"} ke sure to handle the cases when the array is empty or if it has a single element. Also, as the very first step, make sure the at: Store the last element in a variable. Then rotate elements right (make sure to start at the correct end of the array). Then Write a meaningful test method for rotateRight based on the JShell session shown above. If using JUnit (not available in the ays a1 and a2 are equal; otherwise you can write your own code to verify the correctness of the resulting array. est nublic void testRotateDight40/

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

using JAVA

We will use the following array to store the frequencies of the word lengths of the input data. I.e., the array indicates how many words have one letter, how many have two letters, etc.
final var MAX_WORD_LENGTH = 33;
final var wordLengthFrequencies = new int[MAX_WORD_LENGTH];
For example, if wordLengthFrequencies[2] == 7, this means that there are seven words of length two.
Write a method with a loop that reads all the words in a String iterator and, for each word, updates the frequency of the corresponding word length.
public static int[] tallyWorldLengths(final Iterator<String> input) {
final var result = new int[MAX_WORD_LENGTH];
// rest is your job!
return result;
}
Transcribed Image Text:We will use the following array to store the frequencies of the word lengths of the input data. I.e., the array indicates how many words have one letter, how many have two letters, etc. final var MAX_WORD_LENGTH = 33; final var wordLengthFrequencies = new int[MAX_WORD_LENGTH]; For example, if wordLengthFrequencies[2] == 7, this means that there are seven words of length two. Write a method with a loop that reads all the words in a String iterator and, for each word, updates the frequency of the corresponding word length. public static int[] tallyWorldLengths(final Iterator<String> input) { final var result = new int[MAX_WORD_LENGTH]; // rest is your job! return result; }
a) Write a static Java method that rotates the contents of a String array to the right by one position (wrapping around from the end to the beginning).
public static void rotateRight(final String[] array) {...}
The method must operate in place, which means that you cannot copy the contents of the array to another list or array and then try to manipulate it. In other words, you are not allowed to use another data
structure that stores the contents of the given array).
Example:
jshell> var I = new String[] { "hello", "world", "what", "up" }
| ==> String[4] { "hello", "world", "what", "up" }
jshell> rotateRight(I)
jshell> I
| ==> String[4] { "up","hello", "world", "what"}
Make sure to handle the cases when the array is empty or if it has a single element. Also, as the very first step, make sure the array is non-null (otherwise throw an IllegalArgumentException).
Hint: Store the last element in a variable. Then rotate elements right (make sure to start at the correct end of the array). Then store the formerly last element
its new place.
b) Write a meaningful test method for rotateRight based on the JShell session shown above. If using JUnit (not available in the JShell), you may find it convenient to use assertArrayEquals(a1, a2), which tests whether
arrays a1 and a2 are equal; otherwise you can write your own code to verify the correctness of the resulting array.
@Test public void testRotateRight4() { ...}
c) Write a meaningful test method for rotateRight based on an array containing a single element.
@Test public void testRotateRight1() { ... }
Transcribed Image Text:a) Write a static Java method that rotates the contents of a String array to the right by one position (wrapping around from the end to the beginning). public static void rotateRight(final String[] array) {...} The method must operate in place, which means that you cannot copy the contents of the array to another list or array and then try to manipulate it. In other words, you are not allowed to use another data structure that stores the contents of the given array). Example: jshell> var I = new String[] { "hello", "world", "what", "up" } | ==> String[4] { "hello", "world", "what", "up" } jshell> rotateRight(I) jshell> I | ==> String[4] { "up","hello", "world", "what"} Make sure to handle the cases when the array is empty or if it has a single element. Also, as the very first step, make sure the array is non-null (otherwise throw an IllegalArgumentException). Hint: Store the last element in a variable. Then rotate elements right (make sure to start at the correct end of the array). Then store the formerly last element its new place. b) Write a meaningful test method for rotateRight based on the JShell session shown above. If using JUnit (not available in the JShell), you may find it convenient to use assertArrayEquals(a1, a2), which tests whether arrays a1 and a2 are equal; otherwise you can write your own code to verify the correctness of the resulting array. @Test public void testRotateRight4() { ...} c) Write a meaningful test method for rotateRight based on an array containing a single element. @Test public void testRotateRight1() { ... }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 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