Write a program that includes in its MainClass the following methods: 1. A method called printArray that takes an array of double values and prints the array elements on the same line with one space between each two elements, then prints a new line. 2. 3. A method called getRandomElement that takes an array of double numbers and returns a random element from the array. A method called shiftArray that takes a double value and an array of double values. The method must shift the array in its place to the right, and insert the double value at index 0. Note that this method must not create a new array, it must rotate the array in its place. For example, if the passed array is 6.5, 2.1, 5.8, 1.5, 8.9 and the passed double value is 3.3, after invoking the method the array must become: 3.3.6.5.2.1, 5.8. 1.5

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

java, please solve parts 1, 2 and 3, thanks sir 

**Write a program that includes in its MainClass the following methods:**

1. **A method called `printArray`** that takes an array of double values and prints the array elements on the same line with one space between each two elements, then prints a new line.

2. **A method called `getRandomElement`** that takes an array of double numbers and returns a random element from the array.

3. **A method called `shiftArray`** that takes a double value and an array of double values. The method must shift the array in its place to the right, and insert the double value at index 0. Note that this method must not create a new array, it must rotate the array in its place.

   For example, if the passed array is 6.5, 2.1, 5.8, 1.5, 8.9 and the passed double value is 3.3, after invoking the method the array must become: 
   3.3, 6.5, 2.1, 5.8, 1.5
Transcribed Image Text:**Write a program that includes in its MainClass the following methods:** 1. **A method called `printArray`** that takes an array of double values and prints the array elements on the same line with one space between each two elements, then prints a new line. 2. **A method called `getRandomElement`** that takes an array of double numbers and returns a random element from the array. 3. **A method called `shiftArray`** that takes a double value and an array of double values. The method must shift the array in its place to the right, and insert the double value at index 0. Note that this method must not create a new array, it must rotate the array in its place. For example, if the passed array is 6.5, 2.1, 5.8, 1.5, 8.9 and the passed double value is 3.3, after invoking the method the array must become: 3.3, 6.5, 2.1, 5.8, 1.5
Expert Solution
Step 1

To generate random number Math.random() method is used which generated number in range 0 to 1(1 excluding).

Say a = Math.random() and a will be some value between 0 to 1

taking integer part of a*n where n is the length of array will result in random index value.

Further comments are included in the program given below, 2 output screenshot is included to show the randomness.

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education