207k views
2 votes
Create a program that has 7 smart functions and each function accepts 3 integer data and return the calculated value. Those functions can calculate the sum, difference, product, quotient, average of the given data. Other functions can return the highest and lowest given data. Turn in your the .java file, screenshots of your source code and the program output in here.

User Arjun G
by
8.5k points

1 Answer

5 votes

Answer:

public class SmartFunctions {

// Function to calculate the sum of three integers

public static int sum(int a, int b, int c) {

return a + b + c;

}

// Function to calculate the difference of three integers

public static int difference(int a, int b, int c) {

return a - b - c;

}

// Function to calculate the product of three integers

public static int product(int a, int b, int c) {

return a * b * c;

}

// Function to calculate the quotient of three integers

public static double quotient(int a, int b, int c) {

return (double) a / (double) b / (double) c;

}

// Function to calculate the average of three integers

public static double average(int a, int b, int c) {

return (double) (a + b + c) / 3.0;

}

// Function to return the highest value among three integers

public static int highest(int a, int b, int c) {

return Math.max(Math.max(a, b), c);

}

// Function to return the lowest value among three integers

public static int lowest(int a, int b, int c) {

return Math.min(Math.min(a, b), c);

}

public static void main(String[] args) {

// Sample input values

int num1 = 10;

int num2 = 5;

int num3 = 7;

// Calculating results using the smart functions

int sumResult = sum(num1, num2, num3);

int diffResult = difference(num1, num2, num3);

int productResult = product(num1, num2, num3);

double quotientResult = quotient(num1, num2, num3);

double averageResult = average(num1, num2, num3);

int highestResult = highest(num1, num2, num3);

int lowestResult = lowest(num1, num2, num3);

// Printing the results

System.out.println("Sum: " + sumResult);

System.out.println("Difference: " + diffResult);

System.out.println("Product: " + productResult);

System.out.println("Quotient: " + quotientResult);

System.out.println("Average: " + averageResult);

System.out.println("Highest: " + highestResult);

System.out.println("Lowest: " + lowestResult);

}

}

Example Output:

Sum: 22

Difference: -2

Product: 350

Quotient: 0.2857142857142857

Average: 7.333333333333333

Highest: 10

Lowest: 5

User Letmutx
by
8.3k points

No related questions found