public class OrderOfOperations { ArrayList contents; String item; OrderOfOperations check; public static void main (String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter an operation: "); String a = input.nextLine(); OrderOfOperations go = new OrderOfOperations(); a = go.brackets(a); System.out.println("Result: "+a); } public String brackets(String s){ //method which deal with brackets separately check = new OrderOfOperations(); while(s.contains(Character.toString('('))||s.contains(Character.toString(')'))){ for(int o=0; o=0;i--){ if(s.charAt(i)=='('){ //search for a opening bracket String in = s.substring(i+1,o); in = check.recognize(in); s=s.substring(0,i)+in+s.substring(o+1); i=o=0; } } } } if(s.contains(Character.toString('('))||s.contains(Character.toString(')'))|| s.contains(Character.toString('('))||s.contains(Character.toString(')'))){ System.out.println("Error: incorrect brackets placement"); return "Error: incorrect brackets placement"; } } s=check.recognize(s); return s; } public String recognize(String s){ //method divide String on numbers and operators PutIt putIt = new PutIt(); contents = new ArrayList(); //holds numbers and operators item = ""; for(int i=s.length()-1;i>=0;i--){ //is scan String from right to left, if(Character.isDigit(s.charAt(i))){ //Strings are added to list, if scan finds item=s.charAt(i)+item; //a operator, or beginning of String if(i==0){ putIt.put(); } }else{ if(s.charAt(i)=='.'){ item=s.charAt(i)+item; }else if(s.charAt(i)=='-' && (i==0 || (!Character.isDigit(s.charAt(i-1))))){ item=s.charAt(i)+item; //this part should recognize putIt.put(); //negative numbers }else{ putIt.put(); //it add already formed number and item+=s.charAt(i); //operators to list putIt.put(); //as separate Strings if(s.charAt(i)=='|'){ //add empty String to list, before "|" sign, item+=" "; //to avoid removing of any meaningful String putIt.put(); //in last part of result method } } } } contents = putIt.result(contents, "^", "|"); //check Strings contents = putIt.result(contents, "*", "/"); //for chosen contents = putIt.result(contents, "+", "-"); //operators return contents.get(0); } public class PutIt{ public void put(){ if(!item.equals("")){ contents.add(0,item); item=""; } } public ArrayListresult(ArrayList arrayList, String op1, String op2){ int scale = 10; //controls BigDecimal decimal point accuracy BigDecimal result = new BigDecimal(0); for(int c = 0; c