Create a program in Java that has the following functions: add: which takes 2 in
ID: 668902 • Letter: C
Question
Create a program in Java that has the following functions:
add: which takes 2 input numbers and computes their sum
subtract: which takes 2 input numbers and performs their subtraction
multiply: which takes 2 input numbers and computes their product
divide: which takes 2 input numbers and performs their division
add3: which takes 3 input numbers and computes their sum
multiply3: which takes 3 input numbers and computes their product
All numbers can be considered doubles.
In the main program perform THREE mathematical equations using the above functions to demonstrate their use.
For example: double example1 = subtract(100, sum(multiply(2,4), divide(10,2) ) );
Submit the java file that implements all the above in Canvas.
Explanation / Answer
Answer:
public class Equation {
public static void main(String args[])
{
double example1 = sub(100, sum(mul(2,4), div(10,2) ) );
System.out.println("1st Answer =" + example1);
double example2 = sum(200 , sub(34,45),mul(56,23,2));
System.out.println("2nd Answer =" +example2);
double example3 = mul(sum(5,9,div(45,9)),sum(34,45),mul(3,4,5));
System.out.println("3rd Answer =" +example3);
}
static double sum(double a , double b)
{
return (a+b);
}
static double sub(double a , double b)
{
return (a-b);
}
static double mul(double a , double b)
{
return (a*b);
}
static double div(double a, double b)
{
return (a/b);
}
static double sum(double a , double b , double c)
{
return (a+b+c);
}
static double mul(double a , double b,double c)
{
return (a*b*c);
}
}
OUTPUT:
1st Answer =87.0
2nd Answer =2765.0
3rd Answer =90060.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.