public int bracket_matcher(String str){

		//Initialize result to 0 by default;
		int result = 0; 
		
		//This List<String> brackets stores the brackets in the input String.
		List <String> brackets = new ArrayList<>();
		//This is a counter for the number of opening brackets
		int open = 0;
		//This is a counter for the number of closing brackets
		int close = 0;
		
		for (int i = 0; i<str.length(); i++){
			if (str.substring(i, i+1).equals("(") || 
					str.substring(i, i+1).equals(")")){
				brackets.add(str.substring(i, i+1));
			}
		}
		
		if (brackets.isEmpty()){
			result = 1;
		}
		else if (brackets.size()%2 == 1){
			result = 0;
		}
		else {
			result = 1;
			for (int j = 0; j<brackets.size(); j++){
				if (brackets.get(j).equals("(")){
					open++;
				}
				if (brackets.get(j).equals(")")){
					close++;
				}
				if (close > open){
					result = 0;
					break;
				}	
			}
		}
		return result;
	}