4. A method called occurrences that takes a double value and an array of doubles as parameters, and returns the number of occurrences of the double value in the array. 5. For example, if the double number 4.1 and the array {1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2} are passed, the method must return the number 3. A method named findElement that takes a double number and an array of double numbers as parameters and returns an array that includes the indices of all the number occurrences in the array. This method must invoke the method occurrences to get how many times the value appears in the array. For example, if the double number 4.1 and the array {1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2} are passed, the method must return the array {1, 4, 5}.

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

Java, please solve parts 4 and 5 please sir and thank you 

**Title: Implementing Essential Methods in Java**

**Introduction:**
In this exercise, you will write a program that features several essential methods in its `MainClass`. Each method operates on arrays of double values and performs specific tasks, illustrating fundamental concepts in array manipulation, randomization, and searching.

**Methods Overview:**

1. **printArray Method:**
   - **Description:** This method takes an array of double values and prints the elements on the same line, separated by a space. After printing all elements, it moves to a new line.
   - **Purpose:** To display array elements in a formatted manner.

2. **getRandomElement Method:**
   - **Description:** This method accepts an array of double numbers and returns a random element from it.
   - **Purpose:** To demonstrate basic randomization in array handling.

3. **shiftArray Method:**
   - **Description:** This method requires a double value and an array of double values as input. It shifts the array to the right, inserting the specified double value at index 0. Importantly, this method should rotate the array in-place without creating a new array.
   - **Example:** 
     - *Input Array:* `6.5, 2.1, 5.8, 1.5, 8.9`
     - *Double Value:* `3.3`
     - *Output Array:* `3.3, 6.5, 2.1, 5.8, 1.5`
   - **Purpose:** To practice modifying an array's structure and understand rotation.

4. **occurrences Method:**
   - **Description:** This method takes a double value and an array of doubles. It returns the number of times the double value occurs within the array.
   - **Example:** 
     - *Double Number:* `4.1`
     - *Array:* `{1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2}`
     - *Output:* `3`
   - **Purpose:** To learn to count occurrences of an element in an array.

5. **findElement Method:**
   - **Description:** This method accepts a double number and an array of double numbers. It returns an array containing the indices of all occurrences of the specified number. It must invoke the `occurrences` method to
Transcribed Image Text:**Title: Implementing Essential Methods in Java** **Introduction:** In this exercise, you will write a program that features several essential methods in its `MainClass`. Each method operates on arrays of double values and performs specific tasks, illustrating fundamental concepts in array manipulation, randomization, and searching. **Methods Overview:** 1. **printArray Method:** - **Description:** This method takes an array of double values and prints the elements on the same line, separated by a space. After printing all elements, it moves to a new line. - **Purpose:** To display array elements in a formatted manner. 2. **getRandomElement Method:** - **Description:** This method accepts an array of double numbers and returns a random element from it. - **Purpose:** To demonstrate basic randomization in array handling. 3. **shiftArray Method:** - **Description:** This method requires a double value and an array of double values as input. It shifts the array to the right, inserting the specified double value at index 0. Importantly, this method should rotate the array in-place without creating a new array. - **Example:** - *Input Array:* `6.5, 2.1, 5.8, 1.5, 8.9` - *Double Value:* `3.3` - *Output Array:* `3.3, 6.5, 2.1, 5.8, 1.5` - **Purpose:** To practice modifying an array's structure and understand rotation. 4. **occurrences Method:** - **Description:** This method takes a double value and an array of doubles. It returns the number of times the double value occurs within the array. - **Example:** - *Double Number:* `4.1` - *Array:* `{1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2}` - *Output:* `3` - **Purpose:** To learn to count occurrences of an element in an array. 5. **findElement Method:** - **Description:** This method accepts a double number and an array of double numbers. It returns an array containing the indices of all occurrences of the specified number. It must invoke the `occurrences` method to
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