Question: I need help creating a new class MathOP2 that Inherits from MathOP. I need to add multiply method and divide method, both methods accepting two

I need help creating a new class MathOP2 that Inherits from MathOP. I need to add multiply method and divide method, both methods accepting two parameters and return a value.

 

And creating a test program with documentation to test all operators (+, -, /, and *)

 

Here is my MathOP so far:

 

class MathOP
{

    int MathAdd(float a,float b)
    {

         return (int) (a+b);
    }


    int MathSub(float a,float b)
    {


         return (int) (a-b);
    }
}

 

And here is my Test program thus far:

 

import java.util.Scanner;
class TestMathOP
{

public static void main(String[] args)
{

Scanner sc = new Scanner(System.in);

while (true)
  {


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

float first = sc.nextFloat();

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

float second = sc.nextFloat();
 

          System.out.print("Enter Operator:");
         
          MathOP c = new MathOP();

         char choice=sc.next().charAt(0);
        //Output answers
         if(choice== '+')
         {

              System.out.print("The answer is: "+c.MathAdd(first, second));
          }    
             
         else
         {
              System.out.print("The answer is: "+c.MathSub(first, second));

          }    

     System.out.print("Do you want another operation (Y/N)? ");

      if(sc.next().charAt(0)=='N')
      {

          System.out.println("Thanks for using our system");

        break;

      }

    }

 }

}

Step by Step Solution

3.41 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the updated MathOP2 class that inherits from MathOP and includes the multiply and divide metho... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!