Access over 35 million academic & study documents

3 Write a class named Calculator with static methods for following

Content type
User Generated
Rating
Showing Page:
1/3
3. Write a class named Calculator with static methods for
following operations
compute and return average of two parameterized integers
compute and return average of two parameterized doubles
multiply and return two parameterized integers
multiply and return two parameterized doubles
use overloading technique.
Solution
Calculator.java
public class Calculator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int intAvg = average(5,5);
System.out.println(\"The average of two integers :
\"+intAvg);
double douAvg = average(5.5,5.5);
System.out.println(\"The average of two doubles :

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
\"+douAvg);
int intMul =multiply(5,5);
System.out.println(\"The multiply of two integers :
\"+intMul);
double douMul =multiply(5.5,5.5);
System.out.println(\"The multiply of two doubles :
\"+douMul);
}
public static int average(int a, int b){
return (a+b)/2;
}
public static double average(double a, double b){
return (a+b)/2;
}
public static int multiply (int a, int b){
return (a*b);
}
public static double multiply (double a, double b){
return (a*b);
}
}
Output:
The average of two integers : 5
The average of two doubles : 5.5

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
3. Write a class named Calculator with static methods for following operations compute and return average of two parameterized integers compute and return average of two parameterized doubles multiply and return two parameterized integers multiply and return two parameterized doubles use overloading technique. Solution Calculator.java public class Calculator { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int intAvg = average(5,5); System.out.println(\"The average of two integers : \"+intAvg); double douAvg = average(5.5,5.5); System.out.println(\"The average of two doubles : \"+douAvg); int intMul =multiply(5,5); System.out.println(\"The multiply of two integers : \"+intMul); double douMul =multiply(5.5,5.5); System.out.println(\"The multiply of two doubles : \"+douMul); } public static int average(int a, int b){ return (a+b)/2; } ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
This is great! Exactly what I wanted.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4