Design and implement an abstract base class


Design and implement an abstract base class ArithmeticExpression that represent any binary (having two arguments) arithmetic expression. In this coursework you will be implementing various subclasses of this class. The abstract class should include at least two methods called evaluate and display which are described below. (15 marks). 2. Design and implement concrete (non-abstract) classes which are subclasses of the class ArithmeticExpression and each one represents some simple arithmetic expression. The operations that you should implement for each subclass should include the binary (i.e. accepting exactly two arguments) operations of addition, subtraction, multiplication and division (all of them accepting double type arguments). Using the classes you should be able to represent an arbitrary expression (i.e. an expression with an arbitrary number of terms), for example an expression like "(5.0+8.1)*(2.0)" or "((5.0+8.1)*(2.0))/12.5" (not specifically in this format but represent the overall expression in an equivalent way). To design your classes you should think what common functionality and differences (fields and methods) these classes share and place such functionality at the appropriate place of the class hierarchy. Implement methods evaluate and display. Method evaluate evaluates the arithmetic expression that the object represents and returns the result as a double. For exam- ple, calling it in an object representing expression "(5.0+8.1)*(2.0)" should return 26.2. Method display prints the raw (unevaluated) expression on the screen. For example, calling it in an object representing expression "(5.0+8.1)*(2.0)" should display the string "(5.0+8.1)*(2.0)" (without the quotes). You shoud NOT use static methods! (45 marks) 3. Implement a test class CalculatorTest which tests the functionality of your classes (the methods of your classes should be called and make sure that they do what they are supposed to do). (10 marks). 1 4. Implement a class RandomCalculations which automatically creates a random number of random expressions and uses your classes above to evaluate and display them. Every time that this class is run, a different number of different random expressions is evaluated and displayed. Test its functionality by calling its methods in the CalculatorTest class above

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Design and implement an abstract base class
Reference No:- TGS0117372

Expected delivery within 24 Hours