/**
*
* @param formula
* @return
*/
public static double accountMinusAndAdd(String formula)
{
Shed shed = new Shed();
char[] c = formula.toCharArray();
String tmp = "";
boolean isAcc = false;
for(int i = 0; i < c.length; i++)
{
if(c[i] == '+' || c[i] == '-')
{
//
if(isAcc)
{
String operator = shed.get();
String strX = shed.get();
double x = Double.parseDouble(strX);
double y = Double.parseDouble(tmp);
tmp = "" + account(x, y, operator);
isAcc = false;
}
else
{
isAcc = true;
}
shed.put(tmp);
shed.put(c[i] + "");
tmp = "";
continue;
}
tmp += c[i];
}
shed.put(tmp);
//
if(isAcc)
{
String strY = shed.get();
double y = Double.parseDouble(strY);
String operator = shed.get();
String strX = shed.get();
double x = Double.parseDouble(strX);
tmp = "" + account(x, y, operator);
shed.put(tmp);
}
return Double.parseDouble(shed.get());
}
/**
*
* @param formula
* @return
*/
public static String accountMultiplyAndDivide(String formula)
{
Shed shed = new Shed();
char[] c = formula.toCharArray();
String tmp = "";
boolean isAcc = false;
for(int i = 0; i < c.length; i++)
{
if(c[i] == '*' || c[i] == '/' || c[i] == '+' || c[i] == '-')
{
//
if(isAcc)
{
String operator = shed.get();
String strX = shed.get();
double x = Double.parseDouble(strX);
double y = Double.parseDouble(tmp);
tmp = "" + account(x, y, operator);
isAcc = false;
}
if(c[i] == '*' || c[i] == '/')
{
isAcc = true;
}
shed.put(tmp);
shed.put(c[i] + "");
tmp = "";
continue;
}
tmp += c[i];
}
shed.put(tmp);
//
if(isAcc)
{
String strY = shed.get();
double y = Double.parseDouble(strY);
String operator = shed.get();
String strX = shed.get();
double x = Double.parseDouble(strX);
tmp = "" + account(x, y, operator);
shed.put(tmp);
}
//
String gs = "";
for(int i = 0; i < shed.list.size(); i++)
{
gs += shed.list.get(i);
}
return gs;
}