import java.util.Scanner;
import java.io.*;
public class infixtopostfix {
String fname;
String output = "";
public infixtopostfix(){
System.out.println("starting infixtopostfix() method...");
getFileName();
readFileContents();
}
public int priority(Object x){
if(x.equals('+') || x.equals('-')){
return 1;
}else if(x.equals('*') || x.equals('/')){
return 2;
}else{
return 0;
}
}
public void getFileName() {
Scanner in = new Scanner(System.in);
System.out.println("Enter file name please.");
fname = in.nextLine();
System.out.println("You entered " + fname);
}
public void readFileContents() {
boolean looping;
DataInputStream in;
String line;
int j, len;
stackOb myStack = new stackOb(10);
try {
in = new DataInputStream(new FileInputStream(fname));
looping = true;
while (looping) {
if (null == (line = in.readLine())) {
looping = false;
in.close();
}
else {
myStack.reset();
System.out.println("line: " + line);
len = line.length();
for(int i = 0; i < len; i++){
char c = line.charAt(i);
if(c == ('+') || c == ('*') || c == ('-') || c == ('/')){
while(!myStack.empty() && priority(myStack.peek()) >= priority(c)){
output += myStack.pop();
myStack.push(c);
}
}else if(c == '('){
myStack.push(c);
}else if(c == ')'){
while(!myStack.peek().equals('(')){
}
}
}
}
}
}
catch(IOException e) {
System.out.println("Error " + e);
} //end catch
}
}
this is my code so far for my assignment...the problem i am having is that part that does
while(!myStack.peek().equals('(')){
it has a compile error telling me: Cannot invoke equals(char) on the primitive type char
how do i fix this?