Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java program HarmonicMean (25) If it takes one hose 12 hours to fill a pool, and another hose 4 hours, then together they fill the

Java program

HarmonicMean (25) If it takes one hose 12 hours to fill a pool, and another hose 4 hours, then together they fill the pool in (2 * 4 * 12) / (4 +12) = 6 hours. The harmonic mean of two positive numbers a and b is 2ab/(a + b).

Write a method double harmonicMean(int x, int y) (5)

that returns the harmonic mean of a > 0 and b > 0.

Write another method double arithmeticMean(int x, int y), (5)

that returns the average of a and b.

Finally, include a third method double geometricMean(int x, int y) (5)

that returns the geometric mean of a and b, that is, the square root of a * b.

Test your methods in a main program (10) that reads two positive integers and displays their harmonic mean, arithmetic mean, and geometric mean. For example, if a and b have values 12 and 4, the harmonic mean is 6.0, the arithmetic mean is 8.0, and the geometric mean is 48 = 6.928. Did you notice that the harmonic mean times the arithmetic mean equals the square of the geometric mean? This identity might be helpful to you when you design your methods.

Please enter two integers greater than zero: 4 12

Harmonic Mean is: 6.0000000

Arithmetic Mean is: 8.0000000

Geometric Mean is: 6.9282032

Please enter two integers greater than zero: 3 10

Harmonic Mean is: 4.6153846

Arithmetic Mean is: 6.5000000

Geometric Mean is: 5.4772256

  1. ArrayOperations2D (55)

Write a main program (5) that reads in the dimensions of a two-dimensional array and creates a two-dimensional array with those rows and columns, and then call the methods below in the order listed to produce the output described below.

The additional method are:

  • fillRandom. (5) Accepts a reference to a two-dimensional int array and fills it with random integers from 0 to 99. Has a void return. (you can use Math.random() or a Random class object here.

  • formatPrint. (5) This method should accept a reference to two-dimensional array and print it out row by row. Has a void return.

  • getTotal. (5) This method should accept a reference to two-dimensional array as its argument and return the total of all the values in the array as an int.

  • getAverage. (5) This method should accept a two-dimensional array as its argument and return the average of all the values in the array as a double. It calls calls getTotal and getElementCount in performing this task.

  • getRowTotal. (5) This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row as an int.

  • getColumnTotal. (5) This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the total of the values in the specified column. as an int

  • getHighestInRow. (5) This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the highest value in the specified row of the array as an int.

  • getLowestInRow. (5) This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the sub- script of a row in the array. The method should return the lowest value in the specified row of the array.

  • getElementCount. (5) This method should accept a two-dimensional array and returns the total number of elements in the array as an int.

Demonstrate each of the methods in this program. Each (except for getElementCount, are called from main.

The main program will request the number of rows and columns as input, creates the two-dimensional array, and first calls fillRandom. A sample output is:

Please enter the number of rows and columns in a two dimensional array: 4 5

78 65 72 30 95

60 71 88 41 73

32 74 47 70 27

59 91 80 81 87

Processing the int array.

Total : 1321

Average : 66.05

Total of row 0 : 340

Highest in row 0 : 95

Lowest in row 0 : 30

Total of row 1 : 333

Highest in row 1 : 88

Lowest in row 1 : 41

Total of row 2 : 250

Highest in row 2 : 74

Lowest in row 2 : 27

Total of row 3 : 398

Highest in row 3 : 91

Lowest in row 3 : 59

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

e. What are notable achievements of the group?

Answered: 1 week ago