public static void main(String[] args) { int[] funky = {1, -5, 3, -5, 6, 6, 6, 7, -5}; int expectedFunkyRange = 5; // |6 - 1| = 5 System.out.println("Expected funkyRange of " + Arrays.toString(funky) +         " to be " + expectedFunkyRange + " and got " + funkyRange(funky)); int[] funkyTwo = {6, 6, 4, 4, 4, 2, 2, 8, 4, 1, 1}; int expectedFunkyRangeTwo = 4; // |4 - 8| = 4 System.out.println("Expected funkyRange of " + Arrays.toString(funkyTwo) +         " to be " + expectedFunkyRangeTwo + " and got " + funkyRange(funkyTwo));   Write a static method: public static int WeirdRange(int[] a) that that calculates the difference between the mode and "anti-mode" of an array of integers. This difference should be a positive number (you can use Math.abs to calculate an absolute value). If the array is empty or null, return -1. If the array has only one thing in it, return 0 (since the mode and anti-mode are the same).   Definitions: The mode of an array is the element that occurs the most frequently. For this problem, if there is a tie for the mode, use the largest mode. In the following array: {1, -5, 3, -5, 6, 6, 6, 7, -5}, both 6 and -5 occur 3 times (which is the highest occurrence), but 6 is considered the mode as it is larger than -5.   The anti-mode of an array is the element that occurs the least frequently. For this problem, if there is a tie for the anti-mode, use the smallest anti-mode. So in the following array: {1, -5, 3, -5, 6, 6, 6, 7, -5}, 1, 3, and 7 are the least frequently occurring numbers, but we consider 1 to be the anti-mode as it is the smaller than 3 and 7.   Example1: funkyRange({1, -5, 3, -5, 6, 6, 6, 7, -5}) è 5, since the mode is 6 and the anti-mode is 1, and |6 – 1| = 5. Example2: funkyRange{6, 6, 4, 4, 4, 2, 2, 8, 4, 1, 1}. The result should be 4, since 4 is the mode and 8 is the anti-mode and |4 – 8| = 4. Example3: funkyRange. When empty and null arrays.Result should be -1 Example 4:weirdRange An array with one element in it.The result should be 0

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
100%

public static void main(String[] args) {

int[] funky = {1, -5, 3, -5, 6, 6, 6, 7, -5};
int expectedFunkyRange = 5; // |6 - 1| = 5
System.out.println("Expected funkyRange of " + Arrays.toString(funky) +
        " to be " + expectedFunkyRange + " and got " + funkyRange(funky));

int[] funkyTwo = {6, 6, 4, 4, 4, 2, 2, 8, 4, 1, 1};
int expectedFunkyRangeTwo = 4; // |4 - 8| = 4
System.out.println("Expected funkyRange of " + Arrays.toString(funkyTwo) +
        " to be " + expectedFunkyRangeTwo + " and got " + funkyRange(funkyTwo));

 

Write a static method: public static int WeirdRange(int[] a) that that calculates the difference between the mode and "anti-mode" of an array of integers. This difference should be a positive number (you can use Math.abs to calculate an absolute value). If the array is empty or null, return -1. If the array has only one thing in it, return 0 (since the mode and anti-mode are the same).

 

Definitions:

The mode of an array is the element that occurs the most frequently. For this problem, if there is a tie for the mode, use the largest mode. In the following array: {1, -5, 3, -5, 6, 6, 6, 7, -5}, both 6 and -5 occur 3 times (which is the highest occurrence), but 6 is considered the mode as it is larger than -5.

 

The anti-mode of an array is the element that occurs the least frequently. For this problem, if there is a tie for the anti-mode, use the smallest anti-mode. So in the following array: {1, -5, 3, -5, 6, 6, 6, 7, -5}, 1, 3, and 7 are the least frequently occurring numbers, but we consider 1 to be the anti-mode as it is the smaller than 3 and 7.

 

Example1: funkyRange({1, -5, 3, -5, 6, 6, 6, 7, -5}) è 5, since the mode is 6 and the anti-mode is 1, and |6 – 1| = 5.

Example2: funkyRange{6, 6, 4, 4, 4, 2, 2, 8, 4, 1, 1}. The result should be 4, since 4 is the mode and 8 is the anti-mode and |4 – 8| = 4.

Example3: funkyRange. When empty and null arrays.Result should be -1

Example 4:weirdRange An array with one element in it.The result should be 0

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Passing Array as Argument
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
  • SEE MORE 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