Computer Science, asked by bhavanaammu3125, 3 days ago

Implement a class Calculator with the method mentioned below. Methods . findAverage(int number1, int number2, int number3): double Method Description findAverage() < • Calculate the average of three numbers • Return the average rounded off to two decimal digits Test the functionalities using the provided Tester class. Sample Input and Output Sample Input Expected Output 12, 8, 15 11.67 10, 20, 30 20.0 41 S​

Answers

Answered by ananyasaini804
0

Explanation:

import java.util.Scanner;

public class JavaExample {

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

System.out.print("Enter the first number: ");

double num1 = scan.nextDouble();

System.out.print("Enter the second number: ");

double num2 = scan.nextDouble();

System.out.print("Enter the third number: ");

double num3 = scan.nextDouble();

scan.close();

System.out.print("The average of entered numbers is:" + avr(num1, num2, num3) );

}

public static double avr(double a, double b, double c)

{

return (a + b + c) / 3;

}

}

Output: Followin

Attachments:
Answered by qtyasff
8

Answer:

class Calculator {

// Implement your code here

public double findAverage(int number1, int number2, int number3) {

 double average = (double) (number1 + number2 + number3)/3;

 double roundOff = Math.round(average * 100.0) / 100.0;

 System.out.println(roundOff);

 return roundOff;

 

}

}

import java.util.Scanner;

class Tester {

public static void main(String args[]) {

 Calculator calculator = new Calculator();

 try (// Invoke the method findAverage of the Calculator class and display the average

 Scanner sc = new Scanner(System.in)) {

  int number1 = sc.nextInt();

  int number2 = sc.nextInt();

  int number3 = sc.nextInt();

 

  calculator.findAverage(number1, number2, number3);

 }

 

}

}

Explanation:

Similar questions