Question: Write a method int maxProductOfThree ( ) in a class ProductCalculator that finds the maximum product of largest three distinct numbers in a given array.

Write a method int maxProductOfThree() in a class ProductCalculator that finds the
maximum product of largest three distinct numbers in a given array.
Create two classes: ProductCalculator and TestMain.
In the TestMain class:
1. Create an array of size 10.
2. Use Scanner to input numbers into the array.
3. Create an object of the ProductCalculator class and call the
maxProductOfThree() method using this object.
4. Print the maximum product of three largest distinct numbers.
Sample Test cases:
1. Enter the values: 11026387549
The maximum product of three distinct numbers is: 720
(Explanation: The maximum product is obtained from the numbers 10,9, and
8.)
2. Enter the values: 101052316487
The maximum product of three distinct numbers is: 560
(Explanation: The maximum product is obtained from the numbers 10,8 and
7.)
3. Enter the values: -1-1-2-3-1-6-4-8-7
The maximum product of three distinct numbers is: -6
(Explanation: The maximum product is obtained from the numbers -1,-2 and -
3.)
Grading Policy
Creating classes, object, declaring necessary variables and calling of the method
using object -4 points
Creating method with array and logic -4 points
Correct output without any errors-2 points

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!