java code #554
tannie2906
started this conversation in
General
java code
#554
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hai anyone please help me, I can't think anymore
Question 2: [40 marks]
CalculatorMain is provided to you, however you need to create the other class, namely Calculator
class yourself. For this exercise you will create a Calculator class and add some basic functionality
to it. The Basic Calculator is able to evaluate simple arithmetical expressions involving integer
operands and the operators: * , / , + , -.
The functionality of the basic calculator is as follows.
For example, 3 + 4, 2 * 10, 10 / 5, 39 - 47.
space character between each operand and the operator.
the form shown above then the program should return a boolean value.
also output a boolean value in that case too.
Calculator class: [40 marks]
(a) You must create a class called Calculator;
(b) The mandatory attributes are operator (char), operand1 and operand2 (int) and expression
(String);
(c) The constructor:public Calculator() is the default Constructor;
(d) The getter() methods: getter() for each mandatory attribute;
(e) The setExpression() method: pass the expression, i.e. the arithmetic expression to be
evaluated) to the method, and assign it to the class attribute;
(f) The verify() method: the header is as follows - public boolean verify()
i. This method determines whether an expression is a valid expression or not and
returns either true or false;
ii. You may call another method from this method or you may find you don’t need to;
iii. You need to test whether there is a valid operator, a space either side of the operator,
that both operands are valid integer numbers (only integers are used for this
application), and that there is no division by zero;
iv. Only if all tests pass can a true be returned, otherwise the expression cannot be
evaluated as it is not a valid expression;
v. Your operator as well as both operands MUST be assigned / determined as part of
this method;
The evaluate() method: the header is as follows - public int evaluate()
(a) This method evaluates the expression and returns the result as a int;
Beta Was this translation helpful? Give feedback.
All reactions