Home > Back-end >  Consult! Simple calculator program development
Consult! Simple calculator program development

Time:11-18

Basic program has been written, and now want to make the program fault-tolerant ability (processing data overflow problem)
Requirements:
1, add a constant MAX_VALUE, its value for the current allowed maximum accuracy (currently set to 8 Numbers);
2, add a private data member String statusFlag, used to hold the state of the engine, such as "E" is for the mistake, "" on behalf of the normal. The series into a symbolic constant,
3, add a public String status () method, is used to return statusFlag;
Public String status () {
Return statusFlag; }
4, add a public Boolean isError (), if engine processing error condition, it returns true.
5, add a private Boolean isError (double n), used to return to the calculation result is too large;
6, modify the operate method, which can detect the state of the calculator, and makes clear, all_clear can handle statusFlag.

The operate methods:
Public void operate (char nc) {//nc is next opcode (the next operator)
//when the calculator is in a state of abnormal

//when the calculator is in a state of normal
The switch (nc) {
Case 'A' ://nc=All the Clear
AllClear ();
return;//All the Clear
Case 'C://nc=Clear
The clear ();
return;//the Clear
Case 'N' ://sign change (minus)
If (argcnt==1)//operand is 1, the output ans (results), such as input, output 12 12
Ans=- ans;
Else//operand is 2, the output arg (the second operand), minus sign given to the second operand arg=- arg
Arg=- arg;
return;
Default://+ - */=(if there is no any case expression and switching value matching, then control is passed to the default)
Compute ();//in the concrete method is given below
Op=nc;//new opcode, will the next operation assignment to the current operator
}
}

CodePudding user response:

Oh I myself wondering produced results very happy
  • Related