Question: Please help me to convert this code into java following the directions above -----COPYABLE C++ CODE----- /*-----------BinaryOperators.h--------------*/ #ifndef BINARYOPERATIONS_H #define BINARYOPERATIONS_H #include #include #include #include

 Please help me to convert this code into java following thedirections above -----COPYABLE C++ CODE----- /*-----------BinaryOperators.h--------------*/ #ifndef BINARYOPERATIONS_H #define BINARYOPERATIONS_H #include #include#include #include using namespace std; class BinaryOperator { public: BinaryOperator (double op1,double op2): fOp1(op1), fOp2(op2){} virtual double DoOp () const = 0; protected:

Please help me to convert this code into java following the directions above

-----COPYABLE C++ CODE-----

/*-----------BinaryOperators.h--------------*/

#ifndef BINARYOPERATIONS_H

#define BINARYOPERATIONS_H

#include

#include

#include

#include

using namespace std;

class BinaryOperator

{

public:

BinaryOperator (double op1, double op2): fOp1(op1), fOp2(op2){}

virtual double DoOp () const = 0;

protected:

const double fOp1;

const double fOp2;

};

//class BinaryOPerator

class Adder: public BinaryOperator

{

public:

Adder(double op1, double op2) : BinaryOperator(op1, op2){}

virtual double DoOp () const;

};

//class Adder

class Subtractor: public BinaryOperator

{

public:

Subtractor(double op1, double op2) : BinaryOperator(op1, op2){}

virtual double DoOp () const;

};

//class Subtractor

class Multiplier: public BinaryOperator

{

public:

Multiplier(double op1, double op2) : BinaryOperator(op1, op2){}

virtual double DoOp () const;

};

//class Multiplier

class Divider: public BinaryOperator

{

public:

Divider(double op1, double op2) : BinaryOperator(op1, op2){}

virtual double DoOp () const;

};

//class Divider

void Test();

#endif

/*-----------BinaryOperators.cpp--------------*/

double Adder::DoOp() const

{

return fOp1 + fOp2 ;

}

double Subtractor::DoOp() const

{

return fOp1 - fOp2 ;

}

double Multiplier::DoOp() const{return fOp1 * fOp2 ;}

double Divider::DoOp() const

{

if (fOp2 == 0)

{

throw string("Divide by zero");

}

return fOp1 / fOp2 ;

}

void Test()

{

BinaryOperator *bptr;

//3+7

Adder a(3,7);

bptr = &a;

cout DoOp()

// 3-5

Subtractor s(3, 5);

bptr = &s;

cout DoOp()

// 3*7

Multiplier m(3, 7);

bptr = &m;

cout DoOp()

// 3/5

Divider d(3, 5);

bptr = &d;

cout DoOp()

try{

// 3/0

Divider d1(3,0);

bptr = &d1;

cout DoOp()

}

catch(string e)

{

cout

}

}

/*-----------main_binary.cpp--------------*/

int main()

{

Test();

return 0;

}

/*

-----------------output---------------------

Adder output is 10 Subtractor output is -2 Multiplier output is 21 Divider output is 0.6 Divide by zero

*/

(a) Re-code the program in Assignment 3 in Java. (b) Design the try-catch mechanism so that division by zero does not produce wrong output. (b) Run you program and include the output in your submission

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!