Created
March 3, 2018 18:06
-
-
Save allomov/c05f0418e8d2e26a235088ece2831c5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.*; | |
public class Operation { | |
double[] operatorsValues; | |
void setOperatorsValues(double[] values) { operatorsValues = values; } | |
String[] getOperationNames() { | |
return String[]{this.getFirstOperationName(), this.getSecondOperationName()} | |
} | |
String getFirstOperationName() { | |
return "Unknown"; | |
} | |
String getSecondOperationName() { | |
return "Unknown"; | |
} | |
String perform() { | |
return "Ooops!" | |
} | |
} | |
public class SumOperation extends Operation { | |
String getFirstOperationName() { | |
return "first op"; | |
} | |
String getSecondOperationName() { | |
return "second op"; | |
} | |
double perform() { | |
return this.operatorsValues[0] + this.operatorsValues[1]; | |
} | |
} | |
public class DivOperation { | |
String getFirstOperationName() { | |
return "div op 1"; | |
} | |
String getSecondOperationName() { | |
return "div op 2"; | |
} | |
double perform() { | |
return this.operatorsValues[0] + this.operatorsValues[1]; | |
} | |
} | |
public class OperationFactory { | |
static Operation build(code) {} | |
} | |
public class OperationManager { | |
private int operation; | |
public OperationManager(int input) { | |
this.operation = OperationFactory.build(input); | |
} | |
public String[] returnArrayOfOperatorsName () { | |
return this.operation.getOperationNames() | |
} | |
public String doOperation(double[] operators, int decimalRounding) { | |
double result = 0; | |
String sentence; | |
char operationSign = '1'; | |
result = this.operation.perform(); | |
BigDecimal firstOperatorFormatted = new BigDecimal(operators[0]).setScale(decimalRounding, RoundingMode.DOWN); | |
BigDecimal secondOperatorFormatted = new BigDecimal(operators[1]).setScale(decimalRounding, RoundingMode.DOWN); | |
BigDecimal resultFormatted = new BigDecimal(result).setScale(decimalRounding, RoundingMode.DOWN); | |
sentence = (firstOperatorFormatted + " " + operationSign + " " + secondOperatorFormatted + " = " + resultFormatted); | |
return sentence; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment