Question: PQ 0 3 a . Create an Abstract class called BinaryOperation, which has two operands, one operator. ( example: 4 + 5 the operands:

PQ03"a. Create an Abstract class called BinaryOperation, which has two operands, one operator. (example: 4+5 the operands: 4,5 and operator: +)
b. Create abstract methods int compute (void) and void printresult (void) in BinaryOperation. Also create necessary attributes, etc.
c. Create 4 classes extending this abstract class namely: AddBinaryOperation, SubBinaryOperation, MulBinaryOperation and DivBinaryOperation, which does addition, subtraction, multiplication, and division in the compute method.
d. Create another class called BinaryEquationParser which has a static method with signature BinaryOperation parseBinaryOpString (String binOpString)
i. This method parses the user input which is a string like 4+5 and then it creates the appropriate instance (in this case AddBinaryOperation) and populates operands, operator, etc. It returns the instance.
e. Create another class called BinaryMain which only has the main method.
i. Take user input like 4+5 and print the result. In this case, the result is 9.
ii. In main method, you will make a call ONLY to the parseBinaryOpString in the BinaryEquationParser and call compute and printresult appropriately.
Note: In total, this part will have a total of 7 classes including the abstract class
Part -2(Do this in a new file called VariableArityMain.java by copying the code from Part 1 and modifying the classes as necessary)
a. The new abstract class will be called VariableArityOperation
i. As the name suggest, it should support operation on more than two integers
ii. Max up to 5 integers (Hint: you can use an array)
b. For simplicity sake, you can assume that we will only operate on positive integers and we dont need to support mixed expressions (i.e. the variable arity operation only need to work for 4+5+2 or 7*8*9 and not 4+5*2)"

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!