Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program in Java that has the following functions: add: which takes 2 in

ID: 674533 • 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) ) );

So create three equations (i.e. 3 lines of code) like the above.

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Equation
{
   public static double sum(double a,double b)
   {
       return a+b;
   }
  
   public static double subtract(double a,double b)
   {
       return a-b;
   }
  
   public static double divide(double a,double b)
   {
       return a/b;
   }
  
   public static double multiply(double a,double b)
   {
       return a*b;
   }
  
   public static double add3(double a,double b,double c)
   {
       return a+b+c;
   }
  
   public static double multiply3(double a,double b,double c)
   {
       return a*b*c;
   }
   public static void main (String[] args) throws java.lang.Exception
   {
       // your code goes here
       double example1 = subtract(100, sum(multiply(2,4), divide(10,2) ) );
       System.out.println("Result of equation is : "+example1);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote